How to "reset" subviews of scrollview for new items?
Posted
by
Tom Tallak Solbu
on Stack Overflow
See other posts from Stack Overflow
or by Tom Tallak Solbu
Published on 2012-09-22T15:35:40Z
Indexed on
2012/09/22
15:37 UTC
Read the original article
Hit count: 196
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?
© Stack Overflow or respective owner