Hi Folks ,
I have a 31 images with sizes 1448 *2048 . I have to add it on scroll view and swap horizontly on iPad. But problem is when i swap across 6th images . It crashes with memory warning .
I have used the logic of page control example from developer.apple.com. in ViewDidload of this class I have set the scroll view frame same as example of page control.
My page load code function is
- (void)loadPage:(int)page
{
if (page < 0) return;
if (page >= [_imgArray count]) return;
// replace the placeholder if necessary aViewController is NSMutable Array.
ImageViewC *controller = [aViewControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null]) {
controller = [[ImageViewC alloc] initWithImage:[_imgArray objectAtIndex:page]];
//controller.screen = currentPage;
[aViewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}
// add the controller's view to the scroll view
if (nil == controller.view.superview)
{
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[scrollView addSubview:controller.view];
}
}
And scroll funtion is
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
// Switch the indicator when more than 50% of the previous/next page is visible
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.currentPage = floor(scrollView.contentOffset.x / pageWidth) + 1;
// load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling)
[self loadPage:page - 1];
[self loadPage:page];
[self loadPage:page + 1];
if (page == -1)
return;
}
Can any one help me. And Please modify the code how to manage the memory so that i would be able to swap 31 images on this scroll.
Thanks in Advance