我有一个带有多个tableviewcells的viewcontroller。我想使用storyboard从tableviewcell之一移动到另一个viewcontroller。我有一个用于viewcontroller的导航控制器。我没有找到解决这个问题的方法。
答案 0 :(得分:1)
您应该实现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];
}
答案 1 :(得分:1)
如果您想使用storyBoard,那么您可以使用Segue从一个tableview单元格跳转到另一个ViewController,您需要做的是 1)。右键单击并从表格视图单元格拖动到所需的视图控制器,然后释放它,您会看到弹出选择“显示” 2)。单击segue并转到身份检查器并根据需要命名segue标识符 3)。然后你必须编写一个方法prepareFor segue方法,并在那里写if if语句
if (segue.identifier == "your identifier Name")
{
//`enter code here`write your logic of pushing the viewcontroller
}
if的上面代码是swift,你可以用不同的标识符名称重复所有多个tableviewcell的步骤
如果不使用故事板,则使用此方法
if (indexpath.row == 0)
{
//use the push viewcontroller code here
}
您可以检查并推送不同的viewcontrollers
答案 2 :(得分:0)
试试这个..
再次运行代码......