Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigating Backwards through a UINavigationController Error

I have a UINavigationController which goes into a ViewController that loads data. This ViewController then segues to TabViewController. This TabViewController has two tabs, each Tab goes to a different UITableViewController. Those two TableViewController then segue to the same DetailsViewController.
Now when navigating backwards from the DetailVC I get this error:

nested push animation can result in corrupted navigation bar
Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't add self as subview'.

Also both TableViews are set up the same way but the bottom table view begins at the top of the frame so its partial obscured by the navigation bar.

like image 348
Snick Avatar asked Nov 02 '22 11:11

Snick


1 Answers

I have a table view and a search bar controller on it.I created push segue on table view cell and performed push on selecting search item via search controller programatically.When navigated back exception fired.This exception happens when you perform same segue twice at a time.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath*)indexPath
{
if (tableView == self.searchDisplayController.searchResultsTableView)
{

    [self performSegueWithIdentifier:@"showDetail"sender:self];
}
}

Since it was performing same segue twice one for table view cell selection created in storyboard and another for search result cell selection. So check when to perform segue

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
if (self.tableView == self.searchDisplayController.searchResultsTableView)
{

    [self performSegueWithIdentifier:@"showDetail"sender:self];
    return YES;
}

return NO;
}

This worked perfectly.

like image 138
iGauravK Avatar answered Nov 12 '22 18:11

iGauravK