Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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];
    }
}

}

like image 974
Niels Avatar asked May 21 '26 01:05

Niels


1 Answers

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...

like image 152
Roger Avatar answered May 23 '26 15:05

Roger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!