Conditional Destination View Controller from Sections in UITableView

与世无争的帅哥 提交于 2019-12-07 01:19:30

You should setup 2 different cells, each linked to different segues (so they have different identifiers), and each pointing to different view controllers. This will make your code trivial, prevent confusion between classes and use segues as they are intended.

You can do it programatically. In the storyboard, draw your two segues from the view controller (rather than from the cell). Then in didSelectRowAtIndexPath, do something like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        [self performSegueWithIdentifier:@"SegueForSection1" sender:indexPath];
    } else if (indexPath.section == 1) {
        [self performSegueWithIdentifier:@"SegueForSection2" sender:indexPath];
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!