1

I have main UIScrollView with lots off buttons which i create like this:

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]

every button have an image:

UIImage *fileImage = [UIImage imageNamed:@"sun.png"];
[myButton setBackgroundImage:fileImage forState:UIControlStateNormal];

Buttons count could be more than 500. So i need to remove from UIscrollView invisible buttons with images to save memory ?

I believe in this method i need to calculate when UIscrollview is stopped scrolling and for example 20 images are invisible, then i need to remove them and reduce scroller contentOffset.

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

    float bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height;
}

Maybe some one could give me tips on this. Or even have a good bookmarked tutorial.

Streetboy
  • 4,351
  • 12
  • 56
  • 101
  • Hi, i have more then one years of exp. that never release button, it will give you bad excess or crash. you just need to remove from scrollbar. you don't have any other options for button... – Nilesh Kikani Feb 06 '12 at 13:02
  • I didn't met to release. I just want to remove them but in my case it's not so easy because i get images for these button from web. – Streetboy Feb 06 '12 at 13:35

1 Answers1

1

I created a similar thing to this using UIViews in a UIScrollView. When the UIScrollView loads, I set the contentView size of the scrollView to be the size of all the views but only loaded the views that can be seen, then when the user scrolls i added the previous/next views and removed the hidden views.

This question helped me: How to implement UIScrollView with 1000+ subviews? especially akosma's answer

Community
  • 1
  • 1
JDx
  • 2,615
  • 3
  • 22
  • 33