Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 10, 2012, 09:39 PM   #1
igorladessa
macrumors newbie
 
Join Date: Dec 2012
UIScrollview + UIimageviews memory crash

I need to scroll over 200 images. I ahve found a tutorial that says that I can over 1000 images with the tutorial code. The tutorial is:

http://soulwithmobiletechnology.blogspot.com.br/2011/05/how-to-load-1000s-of-uiimageview-on.html?m=1

I followed the tutorial, but when I use 100 images aprox..the app crash with memory warning.

My code is here:

http://pastebin.com/BKmsdXxf

I have already with UIIMagenamed, with initWithContentsOfFile

but the problem persist. Pls , help me!
igorladessa is offline   0 Reply With Quote
Old Dec 10, 2012, 09:42 PM   #2
Ides
macrumors member
 
Join Date: Mar 2012
Well how big are the images you're loading? If they are very large then they will cause memory warnings, if you're loading 100+.
Ides is offline   0 Reply With Quote
Old Dec 11, 2012, 04:43 AM   #3
igorladessa
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Quote:
Originally Posted by Ides View Post
Well how big are the images you're loading? If they are very large then they will cause memory warnings, if you're loading 100+.

1,5 mb
igorladessa is offline   0 Reply With Quote
Old Dec 11, 2012, 08:30 AM   #4
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
Use a tableview if you can. Otherwise set things up so that only a small number of image views exist at a time. Unload the image views when they scroll off.
PhoneyDeveloper is offline   0 Reply With Quote
Old Dec 11, 2012, 09:33 AM   #5
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by igorladessa View Post
1,5 mb
Those are quite large. You might want to consider creating thumbnail versions for display most of the time.

Quote:
Originally Posted by PhoneyDeveloper View Post
Use a tableview if you can. Otherwise set things up so that only a small number of image views exist at a time. Unload the image views when they scroll off.
Yeah, UICollectionView (iOS 6) might be a good solution, if UITableView is not, because it works similar in that cells are reused.
__________________
dejo is offline   0 Reply With Quote
Old Dec 12, 2012, 02:44 PM   #6
igorladessa
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
solved!!

I release all ImageViews and load the current and next imageView, when scrolling!


Code:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint scrollOffset=scrollView.contentOffset;
int pagAtual = scrollOffset.x/scroll.frame.size.width;
if(pagAtual != 0) { //always release all imageViews and load the current and next
for(int iCnt = 0; iCnt < [scroll.subviews count]; iCnt++) {
    UIView *viewLiberar = [scroll.subviews objectAtIndex:iCnt];
 if ([viewLiberar isKindOfClass:UIImageView.class]) {
    [viewLiberar removeFromSuperview];
     viewLiberar = nil;
   }
 }
}

if(pageOnScrollView < ((int)scrollOffset.x/scroll.frame.size.width))
 { 

 //load the next page
[self loadNextPage:(pagAtual)];
[self loadNextPage:(pagAtual + 1)];
 }
else if(pageOnScrollView > ((int)scrollOffset.x/scroll.frame.size.width))
  {
  if(pagAtual>0)[self loadNextPage:((int)scrollOffset.x/scroll.frame.size.width)-1];
    }

     pageOnScrollView=scrollOffset.x/scroll.frame.size.width;
      }
It works!

Last edited by dejo; Dec 12, 2012 at 02:56 PM. Reason: Please use [code] tags.
igorladessa is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
I still have a ton of crash and low memory logs in 7.1 sunking101 iOS 7 13 Apr 1, 2014 11:38 PM
UITableView in UIScrollview IDMah iPhone/iPad Programming 4 Aug 4, 2013 12:25 PM
Help in detecting a touch in UIImageViews adildacoolset iPhone/iPad Programming 2 Feb 9, 2013 01:48 PM
Mac Mini 10.8.2 Crash, Can Anyone Decode This Crash Log? cocacolakid OS X 10.8 Mountain Lion 0 Nov 29, 2012 10:20 PM
iOS 6.0 low memory crash max5peru iOS 6 6 Sep 18, 2012 01:28 PM

Forum Jump

All times are GMT -5. The time now is 12:23 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC