Crashing when loading images into UIScrollView

Discussion in 'iOS Programming' started by jeremyapp, Aug 3, 2009.

  1. jeremyapp macrumors newbie

    Joined:
    Apr 30, 2008
    #1
    Hey,

    I'm making an eBook app that presents a table view for a user to pick a book, and then based on that selection, loads 35 20kb jpg files into a UIScrollView. I seem to be having memory issues (from what I can tell) when the user selects a book. Sometimes it does load a book (although very slowly) and sometimes the app crashes and throws a strange error:

    Code:
    Program received signal:  “0”.
    warning: check_safe_call: could not restore current frame
    
    Here's what the code that lays out my book looks like:

    Code:
    - (void)layoutBook {
    	CGRect workingFrame;
    	
    	workingFrame.origin.x = 0;
    	workingFrame.origin.y = 0;
    	workingFrame.size.height = 480;
    	workingFrame.size.width = 320;
    	
    	int x;
    	for(x=1; x<=35; x++) {
    		UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@%d",currentBook,x] ofType:@"jpg"]];
    		imageView = [[[UIImageView alloc] initWithFrame:workingFrame] autorelease];
    		imageView.image = image;
    		[scrollView addSubview:imageView];
    		workingFrame.origin.x = workingFrame.origin.x + 320;
    		
    	}
    	
    	workingFrame.size.width = workingFrame.origin.x;
    	[scrollView setContentSize:workingFrame.size];
    	
    	workingFrame.origin.x = 0;
    	workingFrame.origin.y = 0;
    	workingFrame.size.width = 320;
    	workingFrame.size.height = 480;
    	
    	[scrollView setFrame:workingFrame];
    }
    
    Does anything look wrong here? Thanks!
     
  2. jeremyapp thread starter macrumors newbie

    Joined:
    Apr 30, 2008
    #2
    Still haven't figured out a good solution yet. My guess is the phone isn't happy loading 35 UIImages. Has anyone come up with a good way to lazy-load images into a UIScrollView? I haven't found much through google or the developer forums yet.
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
  4. jeremyapp thread starter macrumors newbie

    Joined:
    Apr 30, 2008
    #4
    Perfect - Apologies for once again underestimating (and overlooking) the sample projects.

    Good find!
     

Share This Page