Search code examples
objective-ciosxcodeuiviewuitabbar

Back button that pushes to previous view ios


I've got a "settings" type view that I want to be reachable by every view within my tab navigation. I am able to get to the settings view, but how do I program a button that brings you back to the view that brought you there? For example, if I access the settings view from view 1 I want the back button to bring you back to view 1. Then if I access it from view 2, I want the same back button to bring you back to view 2.

Thanks!


Solution

  • Is your view in a navigation controller? If so, use:

    [self.navigationController popViewControllerAnimated:YES];
    

    If it's a modal view controller, use:

    [self dismissModalViewControllerAnimated:YES];