views:

83

answers:

1

hi there.

I'm facing a problem with my scrollview (horizontal, paging enabled, can be 50 pages or more) what i want to do is, load content onto the scrollView's content-View while the user is scrolling horizontally (because initially loading all the content takes way to long).

what i do is: everytime a scrollViewDidScroll happens i check if the loading of additional content is necessary. in case it is, a new "page" is being created and added onto the scrollViews contentview at the correct position.

the problem is: that while it preloads a page, the "scrolling-movement" gets disturbed. the screen doesn't exactly flicker, but the smoothness of the scrolling animation suffers heavily.

in code that is:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[self preLoadPageNumber:self.currentPageIndex + 2];}

-(void)preLoadPageNumber:(int)pageNumber{
NSMutableArray *tmpMovies;
VoDPage *pageView;

if(pageNumber < [self getAmountOfPages])
{       
    pageView = [pageViewControllers objectAtIndex:pageNumber];

    if((NSNull*)pageView == [NSNull null])
    {
        tmpMovies = [[NSMutableArray alloc] initWithCapacity:6];

        for(int o = ((pageNumber) * 6); o < ((pageNumber+1)*6); ++o)
        {
            @try {
                [tmpMovies addObject:[movies objectAtIndex:o]];
            }
            @catch (NSException * e) {
                break;
            }

        }
        pageView = [[VoDPage alloc] initWithContent:tmpMovies andNavCtrl:navCtrl];
        pageView.view.frame = CGRectMake(((pageNumber) * 320)-8 , 0, 320, 332);
        if(editModeEnabled)
            [pageView enableEditMode];

        [scrollView addSubview:pageView.view];

        [pageViewControllers replaceObjectAtIndex:pageNumber withObject:pageView];
    }
}   

}

probably I have to make some design changes here. I'm sure some of you have faced similar problems in the past. Any help / tipps or links are greatly appreciated

thanks in advance for your help

sam

A: 

Ok i somewhat figured out a workaround that does the trick.

i changed the preLoadPageNumber- Method to look like this:

-(void)preLoadPageNumber:(NSNumber*)param

simply because i call a helper method from within ScrollViewDidScroll and said helperMethod looks like this:

-(void)performPreLoadAfterDelay

{

[self performSelector:@selector(preLoadPageNumber:) withObject:[NSNumber numberWithInt:self.currentPageIndex +1] afterDelay:0.001]; 

}

Calling performSelector from within the ScrollViewDidScroll Method doesn't work when scrolling very fast ("blank" pages appear).. I don't really know why, but the trick with the helperMethod worked. Annimation is smooth now and the "blank-page"-problem dissappeared.

samsam