我是ios编程的新手。我有多个视图控制器。我首先显示tableView控制器,之前有一个导航控制器..我想根据所选的单元显示特定的视图控制器..我已将tableView控制器设置为动态和原型Cell 为1 我有segue连接从表到我的视图控制器名称之一 APP1ViewController 我有另外两个控制器名称APP2和APP3 ..如何连接它们,以便在特定的单元格特定的视图控制器上加载。 这是显示单元格的代码..目前我的表中有一个部分和三行
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"AppCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
switch (indexPath.row)
{
case 0:
cell.textLabel.text = @"APP 1 ";
cell.detailTextLabel.text = @"Detail of App 1...";
break;
case 1:
cell.textLabel.text = @"App2";
cell.detailTextLabel.text = @"Detail of App 2 app...";
break;
case 2:
cell.textLabel.text = @"App3";
cell.detailTextLabel.text =
@"Detail of App 3...";
break;
default:
cell.textLabel.text = @"Unkown";
cell.detailTextLabel.text = @"Unknown";
break;
}
return cell;
}
答案 0 :(得分:7)
从具有表的控制器而不是从表或单元本身创建三个segue。为每个segue提供唯一标识符。在tableView:didSelectRowAtIndexPath:
中,调用表视图控制器的performSegueWithIdentifier:sender:
方法,并选择与所选行匹配的标识符。
答案 1 :(得分:5)
试试这个,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"your storyboard" bundle:nil];
UIViewController *viewController = nil;
switch (indexPath.row) {
case 0:
viewController = [storyboard instantiateViewControllerWithIdentifier:@"viewController1"];
break;
case 1:
viewController = [storyboard instantiateViewControllerWithIdentifier:@"viewController2"];
break;
case 2:
viewController = [storyboard instantiateViewControllerWithIdentifier:@"viewController3"];
break;
default:
viewController = [storyboard instantiateViewControllerWithIdentifier:@"viewController4"];
break;
}
[[self navigationController] pushViewController:viewController animated:YES];
}
答案 2 :(得分:1)
实施Tablview的委托方法之一
tableView:didSelectRowAtIndexPath:
并且在上面的委托方法中,您可以从故事板中获取特定视图控制器并实例化并推送到导航控制器,如下所示
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"your storyboard" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Your Storyboard's identifier that you want to push"];
[[self navigationController] pushViewController:viewController animated:YES];