Dynamically showing TableView or DetailView

Posted by Niels on Stack Overflow See other posts from Stack Overflow or by Niels
Published on 2012-06-03T08:05:24Z Indexed on 2012/06/04 22:40 UTC
Read the original article Hit count: 170

Filed under:
|
|
|

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

}

© Stack Overflow or respective owner

Related posts about ios

Related posts about xcode