【问题标题】:iPhone: Waiting until selectrow animation finishes before pushing viewcontroller?iPhone:在推送视图控制器之前等到选择行动画完成?
【发布时间】:2010-03-13 21:59:53
【问题描述】:

我的代码如下所示:

NSIndexPath *ip = [NSIndexPath indexPathForRow:15 inSection:0];
[[self tableView] selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionMiddle];

// Pause needed here until animation finishes

[[self navigationController] pushViewController:secondView animated:YES];

现在它动画行的滚动/选择并同时推动视图控制器。我希望它做的是等到它完成滚动/选择,然后推送视图控制器。有什么可能的方法吗?谢谢

【问题讨论】:

    标签: iphone xcode uitableview animation


    【解决方案1】:

    滚动结束时,tableview 应该调用 scrollViewDidEndScrollingAnimation。尝试将 push 放入该方法中:

    - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
    {
        if (weShouldPushSecondView)
        {
            weShouldPushSecondView = NO;
            [[self navigationController] pushViewController:secondView animated:YES];
        }
    }
    

    您可能需要在 selectRowAtIndexPath 之后使用设置为 YES 的 bool ivar,因为在其他时间可能会为其他滚动调用 scrollViewDidEndScrollingAnimation。

    【讨论】:

    • 这几乎是完美的!它唯一没有捕捉到的是该行是否已经在屏幕上,因此不需要滚动即可到达它。在这种情况下,它只突出显示单元格并且不调用此方法。反正有这个吗?
    • 试试这个:调用 indexPathsForVisibleRows 并查看您选择的单元格是否在数组中。如果是,请在此处调用推送(并且不要将 weShouldPushSecondView 设置为 YES)。如果单元格不在可见列表中,则将 weShouldPushSecondView 设置为 YES(并且不要在此处调用 push 并在滚动完成时调用它)。您可能希望将 bool 的名称更改为 pushSecondViewAfterScroll。
    【解决方案2】:

    您是否有理由不在 -tableView:didSelectRowAtIndexPath: 委托方法中推送视图控制器?动画完成后应该调用该方法。

    【讨论】:

    • didSelectRowAtIndexPath 在 selectRowAtIndexPath 之后根本没有被调用,这就是我在这里单独推送视图控制器的原因
    猜你喜欢
    • 2012-12-22
    • 1970-01-01
    • 2016-08-10
    • 1970-01-01
    • 2012-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多