I have a UIView with three UIScrollViews. I load each with custom UIImageViews that already have their images assigned. The custom UIImageViews are simple and only introduce a few new properties that allow for tracking the imageviews within the scrollviews.
Images load from disk very fast. The code below executes very fast but I have to wait about six seconds per imageview before anything will appear in a scrollview. If I try to load all images, the app will crash with
Program received signal: “0”.
Usually it is an out of memory error. The photos are coming from the phone's photo library. Looking at the images used in the simulator, they range from 213KB to 401KB. I'm obviously doing something wrong but not sure what.
I could probably use a tableview since it does allow paging but I'm not sure if a tableview will have any better performance. I imagine the scrollview issue is that all imageviews must be loaded at once in a scrollview rather than lazily. Since the imageviews are already loaded into a (singleton) dictionary, why does it take so long to load them into a scrollview? All of the UI was done in IB.
In general, is there a better approach?
Here is the code that loads the imageviews into scrollviews:
- (void) addImageViewsToScrollView:(NSMutableDictionary*)imageViews scrollView:(UIScrollView*)scrollView
{
int widthRunningTotal = 0;
int count = 0;
for(NSString *s in [imageViews allKeys]){
CustomImageView *myImageView = [imageViews valueForKey:s];
myImageView.imageName = s;
myImageView.imageId = count;
myImageView.frame = CGRectMake(widthRunningTotal, 0, 160, 100);
myImageView.contentMode = UIViewContentModeScaleAspectFit;
[scrollView addSubview:myImageView];
widthRunningTotal += 160;
count++;
}
scrollView.contentSize = CGSizeMake(widthRunningTotal, 100);
}