David
David

Reputation: 319

swipe gestures and navigation controllers

I currently have an app that has 50 or so custom buttons contained in a scroll view. These are all connected with a navigation controller to individual view controllers to show a full screen picture of the button with a title. I would like to be able to swipe between view controllers but when I do this the back button will then take me back through all of the swipes and not back to the original menu. Is there a tidier way of doing all of this as that many views is also killing my mac?

Thanks

Upvotes: 0

Views: 552

Answers (1)

apascual
apascual

Reputation: 2980

First of all, I think would have been better to use UICollection instead of buttons, but anyway...

This is the answer you want to read:

You can set your own "Back button" and perform the task of getting back to the first UIViewController when it is pressed

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Atrás", nil) style:UIBarButtonItemStylePlain target:self action:@selector(backPressed:)];
     self.navigationItem.leftBarButtonItem = btn;
}


-(void)backPressed: (id)sender
{  
    // Go back to your first view
}

This is the answer you should follow:

Swiping through different UIViews that would render the same thing (image + text) is not a good idea: first, because you are wasting a lot of memory, and secondly, because if have to make any change, it would be tedious...

So, what you should do is use just ONE UIView, and when you detect the swipe gesture you just change what is being rendered in the view, this way your back button will always go back correctly.

Upvotes: 1

Related Questions