iPhone:在推动viewcontroller之前等待selectrow动画完成?

问题描述:

我的代码如下所示:iPhone:在推动viewcontroller之前等待selectrow动画完成?

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

现在它的动画行的滚动/选择和推动,同时视图控制器。我希望它做的是等到它完成滚动/选择,然后推动视图控制器。有没有可能的方法来做到这一点?谢谢

当滚动结束时,tableview应该调用scrollViewDidEndScrollingAnimation。尝试把推该方法:

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

您可能需要使用您的selectRowAtIndexPath后立即设置为YES,因为scrollViewDidEndScrollingAnimation可以在其他时间用于其它卷轴被称为布尔伊娃。

+0

这几乎是完美的!它无法捕捉的唯一情况是该行已经在屏幕上,因此不需要滚动来实现。在这种情况下,它只会突出显示单元格,而不会调用此方法。有没有办法解决? – Mike 2010-03-14 08:51:55

+0

试试这个:调用indexPathsForVisibleRows,看看你选择的单元格是否在数组中。如果是,请在那里调用push(并且不要将weShouldPushSecondView设置为YES)。如果单元格不在可见列表中,则将weShouldPushSecondView设置为YES(并且不要在该处调用该按钮,并在滚动完成时调用它)。您可能想要将bool的名称更改为pushSecondViewAfterScroll。 – DyingCactus 2010-03-14 15:09:07

是否有一个原因,你不在-tableView:didSelectRowAtIndexPath:委托方法中推视图控制器?该方法应该在动画完成后调用。

+0

didSelectRowAtIndexPath在selectRowAtIndexPath之后没有被调用,这就是为什么我在这里单独推视图控制器的原因 – Mike 2010-03-13 22:48:52