简体   繁体   中英

Using multiple detail views with TableView

Im trying to implement a table view page within my tabbed bar application. I have successfully made a table view containing data, and I want this to take me to a detail view. However I want separate detail views for each Cell, to allow me to create more detailed detail views using the UI. I have given the Seque's unique IDs to try and do this.

Currently it crashed every time I press the button, taking me to main.m

Here is the code I have:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
            [self performSegueWithIdentifier:@"showDetail1" sender:self];
            break;
        case 1:
            [self performSegueWithIdentifier:@"showDetail2" sender:self];
            break;
        case 2:
            [self performSegueWithIdentifier:@"showDetail3" sender:self];
            break;
        case 3:
            [self performSegueWithIdentifier:@"showDetail4" sender:self];
            break;
        default:
            break;
     }
}

The exception I get is:

"Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'showDetail2'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'"

Thanks!

The ViewController where you have added your tableView , should be a part of a NavigationController . A ViewController can only be pushed if it is a part of NavigationController . Else try using Present Segue .

Solution 1:

Make your present ViewController in which you have added your tableView a part of NavigationController

If you are using StoryBoard , then select your ViewController in which you have added the tableView. With the Controller selected, choose Editor\\Embed In\\Navigation Controller

Solution 2:

If you do not want to use Navigation/Push design then you can present the ViewController . For that you have to use Present Segues .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM