didSelectRowAtIndexPath和segues [英] didSelectRowAtIndexPath and segues
问题描述
我正在使用Storyboard.我对将新的UItableViewController推入导航堆栈时使用segues感到怀疑.怎么做对?当单元格中的轻击导致推入并仅使用didSelectRowAtIndexPath吗? 请分享您的意见.
I am working with Storyboard. I am in doubt regarding the use of segues when pushing a new UItableViewController onto the navigation stack. How to do it right? No segue when the push results from a tap in a cell and just use didSelectRowAtIndexPath? Please share your opinion.
推荐答案
您根本没有提到它,但是从您提到的segue
来看,您正在使用情节提要.
You do not mention it at all, but judging by your mention of a segue
you are using storyboarding.
使用情节提要时,有一种显示新视图控制器的新方法.通过使用UITableViewCell
连接到Interface Builder中的新视图控制器.这样做时,无需使用didSelectRowAtIndexPath:
,因为新的视图控制器将自动显示.但是,您可以准备segue
,并在新的视图控制器上设置参数,例如:
When using storyboarding there is a new way to show a new view controller. By connecting a UITableViewCell
using a seque to a new view controller in Interface Builder. When you do that, there's no need to use didSelectRowAtIndexPath:
because the new view controller will be displayed automatically. You can however prepare your segue
, and set parameters on the new view controller for example:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// assumes only one type, more extensive checking before cast to
// make it safer is needed.
MyViewController *viewController = (MyViewController *) segue.destinationViewController;
viewController.detailObject = myModelObject;
}
对于未使用Segue连接的任何Tableview单元,您可以使用普通的tableView:didSelectRowAtIndexPath:
来提供自己的行为.
For any tableview cell that is not connected using a segue you can provide your own behaviour using plain old tableView:didSelectRowAtIndexPath:
.
没有正确的方法,仅使用您认为最简单的方法即可.
There is no correct way, just use whatever seems easiest to you.
这篇关于didSelectRowAtIndexPath和segues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!