从UITableviewcell移动到一个ViewController,并使用故事板
我有一个viewcontroller与多个tableviewcells在其中。我想要使用storyboard从tableviewcell移动到另一个viewcontroller。我有一个viewcontroller的导航控制器。我没有真正找到解决这个问题的方法。从UITableviewcell移动到一个ViewController,并使用故事板
您应该实施didSelectRowAtIndexPath
委托,然后将某些逻辑移至另一个视图控制器。
@interface ViewController()<UITableViewDelegate>
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
AnotherViewControllerClass *vc = [[UIStoryboard storyboardWithName:@"StoryboardNameOfAnotherViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"AnotherViewControllerIdentifier"];
[self.navigationController pushViewController:vc animated:YES];
}
如果你想使用storyBoard,那么你可以使用Segue从一个tableview单元跳转到另一个viewcontroller你必须做的是 1)。右键单击并从你的表格视图单元格拖动到你想要的视图控制器,然后释放它,你会看到一个弹出选择“显示” 2)。点击SEGUE并转到身份检查,并根据需要 3命名SEGUE标识符)。然后,你必须只写在一个方法prepareFor赛格瑞methodand写if语句这样
if (segue.identifier == "your identifier Name")
{
//`enter code here`write your logic of pushing the viewcontroller
}
因为如果上面的代码在迅速,您可以在不使用情节串连图板,然后用这个方法
if (indexpath.row == 0)
{
//use the push viewcontroller code here
}
每个索引路径,您可以检查,推动不同势重复这些步骤你有不同势标识符名称的所有多个tableviewcell
六ewcontrollers
我不想去继续 – meowsush
你的意思是通过点击一个UITableViewCell从VC移动到另一个VC? – Hezron
是的,当我选择单元格时,它应该移动到VC – meowsush
实现'didSelectRowAtIndexPath'委托。当你点击一个单元格时,控制会进入这个方法。在那里写入计算逻辑并导航到相应的视图控制器。 – pkc456