Greetings,
I've got a UIScrollView that can contain 50-100+ pages, each of which have a FDMCardViewController (my own class which basically consists of a NIB with a UIImageView that loads a full-screen .png file per page). I am aware that only the controller/view for the current page plus those to the L and R really need to be in memory/the UIScrollView, which is what I'm trying to achieve with the code below. Even thought it's not the most efficient page loading implementation (as it reloads all 3 pages each time), I think I am being thorough in purging all of the previous controllers/views each time. Nevertheless, memory usage steadily climbs and the app grinds to a halt as you progressively scroll through the pages. Additionally, the console log shows that the array I'm using to contain the in-use controllers isn't really functioning properly (always has a count of zero).
Can anyone see any glaring errors and/or suggest any sample code/projects that successfully implement a UIScrollView with large numbers of pages?
Thanks, Joel
Code:
-(void)loadScrollViewPageSandwich:(NSInteger)pageIndex
{
NSLog(@"ViewController Count Inbound: %i", [self.cardViewControllerArray count]);
for (FDMCardViewController* thisViewController in self.cardViewControllerArray)
{
[thisViewController.view removeFromSuperview];
NSLog(@"Releasing view controller: %@", thisViewController);
[thisViewController release];
}
[self.cardViewControllerArray removeAllObjects];
for (id thisSubview in [self.scrollView subviews])
{
NSLog(@"Removing subview: %@", thisSubview);
[thisSubview removeFromSuperview];
}
for (int n = pageIndex - 1; n < pageIndex + 2; n++)
{
int localIndex = n;
if (localIndex < 0) localIndex = 0;
if (localIndex >= self.pageControl.numberOfPages) localIndex = self.pageControl.numberOfPages - 1;
FDMCardViewController* cardViewController = [[FDMCardViewController alloc] initWithPageNumber:localIndex];
cardViewController.delegate = self;
cardViewController.pageObject = [[self enabledCardsArray] objectAtIndex:localIndex];
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * localIndex;
frame.origin.y = 0;
cardViewController.view.frame = frame;
[scrollView addSubview:cardViewController.view];
NSLog(@"Adding this view controller: %@", cardViewController);
[self.cardViewControllerArray addObject:cardViewController];
}
NSLog(@"ViewController Count Outbound: %i", [self.cardViewControllerArray count]);
}
Quote:
2010-02-12 18:49:42.158 FDM_v2.0.35x[648:20b] ViewController Count Inbound: 0
2010-02-12 18:49:42.158 FDM_v2.0.35x[648:20b] Removing subview: <UIView: 0x156bde0; frame = (1280 0; 320 372); autoresize = RM+BM; layer = <CALayer: 0x156bb10>>
2010-02-12 18:49:42.159 FDM_v2.0.35x[648:20b] Removing subview: <UIView: 0x156bd90; frame = (1600 0; 320 372); autoresize = RM+BM; layer = <CALayer: 0x156bbb0>>
2010-02-12 18:49:42.159 FDM_v2.0.35x[648:20b] Removing subview: <UIView: 0x156b8c0; frame = (1920 0; 320 372); autoresize = RM+BM; layer = <CALayer: 0x156b6f0>>
2010-02-12 18:49:42.160 FDM_v2.0.35x[648:20b] Adding this view controller: <FDMCardViewController: 0x157af20>
2010-02-12 18:49:42.162 FDM_v2.0.35x[648:20b] Adding this view controller: <FDMCardViewController: 0x155ce30>
2010-02-12 18:49:42.168 FDM_v2.0.35x[648:20b] Adding this view controller: <FDMCardViewController: 0x1532540>
2010-02-12 18:49:42.169 FDM_v2.0.35x[648:20b] ViewController Count Outbound: 0
2010-02-12 18:49:42.949 FDM_v2.0.35x[648:20b] ViewController Count Inbound: 0
2010-02-12 18:49:42.950 FDM_v2.0.35x[648:20b] Removing subview: <UIView: 0x157cf00; frame = (1600 0; 320 460); autoresize = RM+BM; layer = <CALayer: 0x157cc30>>
2010-02-12 18:49:42.951 FDM_v2.0.35x[648:20b] Removing subview: <UIView: 0x157cbb0; frame = (1920 0; 320 460); autoresize = RM+BM; layer = <CALayer: 0x157d0d0>>
2010-02-12 18:49:42.952 FDM_v2.0.35x[648:20b] Removing subview: <UIView: 0x157ca20; frame = (2240 0; 320 460); autoresize = RM+BM; layer = <CALayer: 0x157c740>>
2010-02-12 18:49:42.953 FDM_v2.0.35x[648:20b] Adding this view controller: <FDMCardViewController: 0x1579020>
2010-02-12 18:49:42.954 FDM_v2.0.35x[648:20b] Adding this view controller: <FDMCardViewController: 0x157bff0>
2010-02-12 18:49:42.962 FDM_v2.0.35x[648:20b] Adding this view controller: <FDMCardViewController: 0x1534c80>
2010-02-12 18:49:42.962 FDM_v2.0.35x[648:20b] ViewController Count Outbound: 0
|