当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Setting Specific UITableView rows to push in a specific detail view?

问题描述:

I currently have 7 rows in my UITableView and I'm using segues to push in a detail view. However, I currently have two different view controllers, and want something like this:

If row 1 and 2 are selected push in: "showMenuDetail1"

If row 3 through 4 are selected push in: showMenuDetail2"

This is what I currently have: I'm not sure how to exactly assign rows to a specific one.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if ([segue.identifier isEqualToString:@"showMenuDetail1"]) {

NSIndexPath *indexPath = [self.menuTableView indexPathForSelectedRow];

HomeDetailViewController *HDViewController = segue.destinationViewController;

HDViewController.theName = [[menu objectAtIndex:indexPath.row] name];

}

}

Any help would be appreciated! I know it's an if and else statement but I'm not sure how to write out the exact condition. Thanks!

网友答案:

Create two segues. The important idea is to not attach either to the table view cells, instead drag them both from the view controller containing the table to their respective destinations. Give them each an identifier.

Then in tableView:didSelectRowAtIndexPath:, examine the indexPath.row and trigger the appropriate segue.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row < 2) { // or whatever
        [self performSegueWithIdentifier:@"SegueForRows0and1" sender:self];
    }
    // etc...
}

You can still implement prepareForSegue if you need it, including, if you need it, referring to the tableView's indexPathForSelectedRow.

分享给朋友:
您可能感兴趣的文章:
随机阅读: