Here is my code for calling a new view controller that is wrapped in a UINavigationController. I want a simple back button on the restaurantResults controller. My selector does not seem to work. I've tried using pop commands. Will those work since I am using presentViewController and not any sort of push?
Pretty sure my selector is wrong right now because it says self.navigationController, which can't possibly be right.
Here is where I call the new view controllers and set up the back button:
 - (void)searchBarSearchButtonClicked:(UISearchBar *)foodNearSearchBar
{
 restaurantsViewController *restaurantResults = [[restaurantsViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:restaurantResults];
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
                                                                   style:UIBarButtonItemStyleBordered
                                                                  target:nil
                                                                  action:@selector(backPressed:)];
    restaurantResults.navigationItem.leftBarButtonItem = backButton;
    [self presentViewController:navController animated:YES completion:Nil];
}
Here is my selector:
   -(void)backPressed: (id)sender
{
    [self.navigationController popViewControllerAnimated: YES]; // or popToRoot... if required.
}
I also tried:
 - (void)backPressed:(id)sender
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    };
                UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
                                                        style:UIBarButtonItemStyleBordered
                                                       target:nil
                                                        ction:@selector(backPressed:)];
restaurantResults.navigationItem.leftBarButtonItem = backButton;
these code should be used on the restaurantsViewController; the target is self.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With