【问题标题】:iOS UITableview Scrolling stop half wayiOS UITableview 滚动中途停止
【发布时间】:2017-02-02 05:48:01
【问题描述】:

当用户点击 tabbar 按钮时,我需要将我的 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 次才能滚动到顶部。有什么需要我检查的吗?在我的其他项目中,这没关系。对于这个,我使用自调整大小的单元格。

【问题讨论】:

    标签: ios uitableview scroll


    【解决方案1】:

    如果您至少有一行,则可以使用以下代码

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tblListing scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    

    【讨论】:

    • 谢谢。它正在配合您的建议。我仍然需要找出我的内容偏移方法不起作用的原因。
    • 让我看看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-23
    • 2014-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 2023-03-20
    相关资源
    最近更新 更多