开发者

TableFooterView calling problem (hard to explain here XD)

i have Load more button with TableFooterView and when i scroll down to the last cell its Automatically load more cells to the table. so Its Working but there is kind of bug if i scroll down to the last cell and i dont release my finger off the screen and scroll up and then down (without releasing my finger) its called the void again so its 2 times.

code:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (([scrollView contentOffset].y + scrollView.frame.size.height) == [scrollView   contentSize].height) {
    [[self footerActivityIndicatorView] startAnimating];
    [self performSelector:@selector(stopAnimatingFooter) withObject:nil afterDelay:0.5];

    return;
}       

}


- (void) stopAnimatingFooter{
//add the data
[[self footerActivityIndicatorView] stopAnimating];
[self addIte开发者_StackOverflow社区msToEndOfTableView];
[[self tableView] reloadData];

}


- (void) addItemsToEndOfTableView{
NSLog(@"test 123 test 123");


// Parse
NSURL *feedURL = [NSURL URLWithString:@"http://gdata.youtube.com/feeds/api/users/RayWilliamJohnson/uploads?v=2&alt=rss&sort_field=added&start-index=21&max-results=20"];
feedParser = [[MWFeedParser alloc] initWithFeedURL:feedURL];
feedParser.delegate = self;
feedParser.feedParseType = ParseTypeFull; // Parse feed info and all items
feedParser.connectionType = ConnectionTypeAsynchronously;
[feedParser parse];





return;

}

i need to find a way that even if i "play" with the last cell its called only once until the task is over and the enable it again.

tnx


I suggest to declare variable, for example, BOOL working; in you UIViewController which implements stopAnimatingFooter and set it to yes: working = YES; if it is not set yet and set it to no:working = NO; when you want to load new cells. When you will enter method stopAnimatingFooter check if this variable is already set if (working) return;.

Don't forget to set in your init method working = NO;

- (void) stopAnimatingFooter
{
    if (working) return;
    working = YES;
    //add the data
    [[self footerActivityIndicatorView] stopAnimating];
    [self addItemsToEndOfTableView];
    [[self tableView] reloadData];
    working = NO;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜