Note that there are some explanatory texts on larger screens.

plurals
  1. POUIScrollView doesn't release images
    primarykey
    data
    text
    <p>I have a UIScrollView that shows a gallery of images from a plist file. I also have a function to delete an image from the gallery image list that basically deletes an object in the plist file and then reload the images in the ScrollView. The issue is I am not able to release the images of the UIScrollView before to reload it with the new content when I use the method <code>- (IBAction)deleteimage:(id)sender</code>. The new content is loaded but over the older content and then the images are still behind the new one. What I should do to release images before to reload the scrollview content? </p> <p>The code I am using is :</p> <pre><code>#import "ImageScrollViewController.h" @interface ImageScrollViewController () @end @implementation ImageScrollViewController @synthesize images,scrollView,pageControl,subview; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. scrollView.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); [self setupthescroll]; self.pageControl.currentPage = 0; } - (void)setupthescroll{ //Get the images of the Array NSUserDefaults *success = [NSUserDefaults standardUserDefaults]; images = [success mutableArrayValueForKey:@"imagelist"]; NSLog(@"list of images%@",images); pageControlBeingUsed = NO; for (int i = 0; i &lt; images.count; i++) { CGRect frame; frame.origin.x = self.scrollView.frame.size.width * i; frame.origin.y = 0; frame.size = self.scrollView.frame.size; subview = [[UIImageView alloc] initWithFrame:frame]; NSString *str4 = [images objectAtIndex:i]; subview.image = [[[UIImage alloc] initWithContentsOfFile:str4] autorelease]; self.subview.contentMode = UIViewContentModeScaleAspectFit; [self.scrollView addSubview:subview]; [subview release]; } self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * images.count, self.scrollView.frame.size.height); self.pageControl.numberOfPages = images.count; //Get the number of the images int page; page = self.pageControl.currentPage; printf("Current Page: %d", page); } - (void)scrollViewDidScroll:(UIScrollView *)sender { if (!pageControlBeingUsed) { // Switch the indicator when more than 50% of the previous/next page is visible CGFloat pageWidth = self.scrollView.frame.size.width; int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; self.pageControl.currentPage = page; } } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { pageControlBeingUsed = NO; } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { pageControlBeingUsed = NO; } - (IBAction)changePage { // Update the scroll view to the appropriate page CGRect frame; frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage; frame.origin.y = 0; frame.size = self.scrollView.frame.size; [self.scrollView scrollRectToVisible:frame animated:YES]; pageControlBeingUsed = YES; } - (IBAction)deleteimage:(id)sender{ //Get the number of the image int page; page = self.pageControl.currentPage; printf("Current Page: %d", page); //Remove the images of the Array NSUserDefaults *success = [NSUserDefaults standardUserDefaults]; images = [success mutableArrayValueForKey:@"imagelist"]; [images removeObjectAtIndex:page]; NSLog(@"list of images%@",images); //Update the Array NSUserDefaults *arrayofimages = [NSUserDefaults standardUserDefaults]; [arrayofimages setObject:images forKey:@"imagelist"]; //Refresh the ScrollView [self setupthescroll]; //post the notification than images have been updated NSUserDefaults *deleted = [NSUserDefaults standardUserDefaults]; [deleted setObject:@"deleted" forKey:@"deletedimages"]; } - (IBAction)closepage:(id)sender{ [self dismissModalViewControllerAnimated:YES]; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)dealloc { [pageControl release]; [scrollView release]; //[images release]; [super dealloc]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload