故事板针对不同的表格视图单元转换到不同的视图控制器
我已经找到了有关创建从一个表视图到另一个视图的过渡的教程。单击单元格时的转换将转到相同的目标视图控制器。我想知道如何为表视图中的每个单元格转换到不同的视图控制器。我还能用情节提要来做到这一点吗?如果是这样,怎么办?如果没有,您可以建议什么替代方案?
故事板已从表格视图连接到详细视图。但这就是我想要完成的:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"mytransition"]) {
NSInteger sectionId = [[self.tableView indexPathForSelectedRow] section];
if (sectionId == 0) {
NSLog(@"try to change the destination view controller");
//I don't know if this is possible?!
} else {
NSLog(@"Proceed with the original destination view controller");
//this is ok
}
}
}
编辑:我找到了解决方案!您可以在这里查看:http://forums.macrumors.com/showthread.php?t =1274743
总之,该解决方案涉及对任何感兴趣的人使用prepareForSegue 和didSelectRowAtIndexPath 的组合。不要将每个单元格链接到另一个视图,而是创建从控制器到每个所需视图控制器的另一个 Segue。然后检查segue 标识符。
-仁
I have been able to find tutorials on creating the transition from one tableview to another view. The transition when you click on a cell is to the same destination view controller. I was wondering how I could transition to different view controllers for each of the cells in the tableview. Can I still do this with storyboard? If so, how? If not, what alternatives can you suggest?
The storyboard has been hooked up from the tableview to a detailed view. But this is what I would like to accomplish:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"mytransition"]) {
NSInteger sectionId = [[self.tableView indexPathForSelectedRow] section];
if (sectionId == 0) {
NSLog(@"try to change the destination view controller");
//I don't know if this is possible?!
} else {
NSLog(@"Proceed with the original destination view controller");
//this is ok
}
}
}
EDIT: I found the solution! You can view it here: http://forums.macrumors.com/showthread.php?t=1274743
In summary, the solution involved using a combination of the prepareForSegue and didSelectRowAtIndexPath for anyone who's interested. Instead of linking each cell to another view, create another segue from the controller to each of the desired view controllers. Then check the segue identifier.
-Jen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
珍是对的。 Jen 链接中的解决方案确实有效。
segue
。didSelectRowAtIndexPath
以获取所选单元格的行号,并使用该单元格的segue
标识符调用performSegueWithIdentifier
。Jen's right. The solution from Jen's link does work.
segue
from the prototype cell in the table to the destination view controller.didSelectRowAtIndexPath
to get the row number of the selected cell, and callperformSegueWithIdentifier
with thesegue
identifier for that cell.