How to "reset" subviews of scrollview for new items?
- by Tom Tallak Solbu
I have a MasterViewController displaying Items. Selecting an Item (ItemA), displays images of ItemA in a DetailViewController. The DeatilViewController contains a scrollView, displaying all the images.
When tableView:didSelectRowAtIndexPath is called, the images is added to an UIImageView, that is tagged and added as a subview to a scrollview.
NSUInteger i;
for (i = 1; i <= numberOfImages; i++)
{
NSString *imageName = [ItemAImages objectAtIndex:i-1];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.tag = i;
[scrollView addSubview:imageView];
}
Works fine. But when I go back to the MasterViewController, and selects a ItemB, the ItemA is still displayed, like the iPhone simulator refuses to forget the previous scrollview,containing ItemA images. I have tried
[subview removeFromSuperview];
which results in either no scrollview at all, or no effect. Depending on when this method is called.
How can I "reset" the scrollview for the next Item?