TableFooterView调用问题(这里很难解释XD)

发布于 2024-12-03 23:39:23 字数 1276 浏览 2 评论 0原文

我有 TableFooterView 的“加载更多”按钮,当我向下滚动到最后一个单元格时,它会自动将更多单元格加载到表格中。 所以它可以工作,但是如果我向下滚动到最后一个单元格并且我不将手指从屏幕上松开并向上然后向下滚动(不松开手指),则会出现某种错误,它再次称为空,因此它是 2 次。

代码:

- (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 addItemsToEndOfTableView];
[[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;

}

我需要找到一种方法,即使我“玩”最后一个单元格,它也只被调用一次,直到任务结束并再次启用它。

tnx

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 addItemsToEndOfTableView];
[[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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随波逐流 2024-12-10 23:39:23

我建议在实现 stopAnimatingFooterUIViewController 中声明变量,例如 BOOLworking; 并将其设置为 yes:working = YES; 如果尚未设置,则在要加载新单元格时将其设置为 no:working = NO;。当您进入方法 stopAnimatingFooter 时,检查此变量是否已设置 if (working) return;

不要忘记在 init 方法中设置 working = NO;

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文