我一直在看几个turorials,如果他们将任何信息传递给下一个视图,他们只用一行代码或更多代码调用新视图。目前我想用这样的segue建立一个菜单:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
if ([path row]==0) {
MainViewController *mtvc = (MainViewController *)[segue destinationViewController];
} else {
SettingsViewController *svc = [segue destinationViewController];
}
}
Normaly所有示例都使用“segue.identifier isEqualToString:@”“”。但我无法将故事板内的表格视图的单元格连接到多个其他视图。因此,我使用选定的行来标识我的哪些视图应该被删除。
我不知道这是否会出现问题,但我以这种方式从我的splashview初始化了tableview:
-(void)turnNext {
UIStoryboard *storyboard = self.storyboard;
MenuTableViewController *mtvc = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];
[self presentViewController: mtvc animated:YES completion:nil];
}
答案 0 :(得分:1)
-(void)turnNext {
UIStoryboard *storyboard = self.storyboard;
MenuTableViewController *mtvc = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];
[self presentViewController: mtvc animated:YES completion:nil];
}
^^^^^^
将其更改为
[self.navigationController pushViewController:mtvc animated:YES];
答案 1 :(得分:1)
你应该为此目的使用segues。
现在,在tableView - ' didselectrowAtIndexPath'方法使用以下。
//use your logic here
if(indexPath.row == 1) {
[self performSegueWithIdentifier:@"segueToMainViewController" sender:nil];
}
else {
[self performSegueWithIdentifier:@"segueToSettingsViewController" sender:nil]
}
如果您需要向控制器提供任何内容,则可以将数据作为发件人传递。