当用户点击标签栏按钮时,我需要将我的tableview滚动到顶部并按我这样设置。
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
UIViewController *vc = ((UINavigationController *)viewController).viewControllers[0];
static UIViewController *previousController = nil;
if (previousController == vc) {
// the same tab was tapped a second time
SEL selector = NSSelectorFromString(@"scrollToTop");
((void (*)(id, SEL))[vc methodForSelector:selector])(vc, selector);
}
previousController = vc; }
- (void)scrollToTop {
[self.tblListing setContentOffset:CGPointZero animated:NO];
}
问题是滚动停止中途并且它不会滚动到顶部。我需要点击2 - 3次才能滚动到顶部。有什么我需要检查的吗?在我的其他项目中,它没关系。对于这个,我使用自我调整单元格。
答案 0 :(得分:1)
如果您至少有一行
,则可以使用以下代码NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tblListing scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];