简体   繁体   中英

Dynamically showing TableView or DetailView

From my TableView I dynamically want to show either a TableView or a DetailView (new segue), based on the cell's content. I setup two segues from the TableView to different DetailViews and one segue from the TableViewCell to the TableView.

I have almost completed the implementation using performSegueWithIdentifier: (see below), but there is one struggling issue remaining: after I call [self dismissModalViewControllerAnimated:YES]; on the DetailView it returns to an empty TableView . I assume because the Storyboard segue from the UITableViewCell is performed. By clicking the back button I return to my original (parent) TableView data.

Any suggestions for this work?

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
    NSString *type = [[self.dataController objectInListAtIndex:[self.tableView indexPathForSelectedRow].row] valueForKey:@"cell_type"];
    NSLog(@"cell_type: %@", type);
    if([[segue identifier] isEqualToString:@"DetailSegue"])
    {
        UIViewController *detailViewController = [segue destinationViewController];        
        detailViewController.game = [self.dataController objectInListAtIndex:[self.tableView indexPathForSelectedRow].row];
    } else if ...
    } else if([[segue identifier] isEqualToString:@"TableViewSegue"]){
    if([type isEqualToString:@"TableView"]){
    //Create child ViewController, a custom ViewController with custom initWithId:Title:
    CategoryViewController *categoryViewController = [[segue destinationViewController] initWithId:categoryId Title:categoryTitle];
    }
}

}

I would create in my tableview multiple cells. Each with its own identifier. Then connect each cell to its own detailviewcontroller. You can also connect a cell to its own view controller (creating drill down functionality for only specific cell).

Thats all...

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