Reputation: 1734
I have a view in which users add data to a table and it can be accessed from several places in the app. But when a user pushes a button in this view, I want him to go back to a specific view, not just any view he came from.
I tried to google this, but none of the methods I found worked.
As I understand, I need to first push the needed view to the stack and then pop to it. But when I did this, all I got was a black screen when the button is pushed.
How to solve this?
Upvotes: 1
Views: 2309
Reputation: 3017
Maybe you can give this a try:
-(void)popToSpecificViewController:(UIViewController *)controller
{
NSMutableArray *mutableVCArray = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[mutableVCArray insertObject:controller atIndex:mutableVCArray.count-1];
[self.navigationController setViewControllers:mutableVCArray animated:NO];
[self.navigationController popViewControllerAnimated:YES];
}
Upvotes: 3
Reputation: 794
you can use segue to push that view controller, you can make it anyway, by the xcode with the ctrl and drag to the specific view to create the segue, or you can do it programatically in the IBAction of the button you mentioned, something like this:
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"DestinationController"];
[self.navigationController pushViewController:controller animated:YES];
Upvotes: 1