TableFooterView调用问题(这里很难解释XD)
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议在实现
stopAnimatingFooter
的UIViewController
中声明变量,例如BOOLworking;
并将其设置为 yes:working = YES;
如果尚未设置,则在要加载新单元格时将其设置为 no:working = NO;
。当您进入方法stopAnimatingFooter
时,检查此变量是否已设置if (working) return;
。不要忘记在
init
方法中设置working = NO;
I suggest to declare variable, for example,
BOOL working;
in youUIViewController
which implementsstopAnimatingFooter
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 methodstopAnimatingFooter
check if this variable is already setif (working) return;
.Don't forget to set in your
init
methodworking = NO;