1
votes

I am using performSegueWithIdentifier() when a button is clicked so that I can pass the right info to my next ViewController. When I click the button, it moves on to a new view blank view and then opens the view that I wanted with the information given with the performSegueWithIdentifier() call. This requires the user to hit the back button 2 times just to get back to the main view.

Is there a way to make sure that prepareForSegue() is not automatically called since I am using performSegueWithIdentifier()? I have a feeling this is happening because I call prepareForSegue() with the performSegueWithIdentifier() call and then it is called a second time automatically.

Here is my code that I use the performSegueWithIdentifier() method:

if (page == 1)
    [self performSegueWithIdentifier:@"time1" sender:self];
else if (page == 2
    [self performSegueWithIdentifier:@"time2" sender:self];
else if (page == 3)
    [self performSegueWithIdentifier:@"time3" sender:self];
else if (page == 4)
    [self performSegueWithIdentifier:@"time4" sender:self];
else if (page == 5)
    [self performSegueWithIdentifier:@"time5" sender:self];
else if (page == 6)
    [self performSegueWithIdentifier:@"time6" sender:self];
else if (page == 7)
    [self performSegueWithIdentifier:@"time7" sender:self];
else if (page == 8)
    [self performSegueWithIdentifier:@"time8" sender:self];
else if (page == 9)
    [self performSegueWithIdentifier:@"time9" sender:self];
else if (page == 10)
    [self performSegueWithIdentifier:@"time10" sender:self];
else if (page == 11)
    [self performSegueWithIdentifier:@"time11" sender:self];
else if (page == 12)
    [self performSegueWithIdentifier:@"time12" sender:self];
else if (page == 13)
    [self performSegueWithIdentifier:@"time13" sender:self];

here is my prepareForSegue() method:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"time1"] ||
        [segue.identifier isEqualToString:@"time2"] ||
        [segue.identifier isEqualToString:@"time3"] ||
        [segue.identifier isEqualToString:@"time4"] ||
        [segue.identifier isEqualToString:@"time5"] ||
        [segue.identifier isEqualToString:@"time6"] ||
        [segue.identifier isEqualToString:@"time7"] ||
        [segue.identifier isEqualToString:@"time8"] ||
        [segue.identifier isEqualToString:@"time9"] ||
        [segue.identifier isEqualToString:@"time10"] ||
        [segue.identifier isEqualToString:@"time11"] ||
        [segue.identifier isEqualToString:@"time12"] ||
        [segue.identifier isEqualToString:@"time13"])
    {
        InfoViewController *ivc = [segue destinationViewController];
        if (_stringText != nil)
            ivc.viewText = _stringText;
    }//end if
}//end prepareForSegue
1
You should try to do all that code with some loops, just a suggestion to improve your code :)LinusGeffarth
@LinusG. Okay thanks but what about the question?sabo
No idea 😄 otherwise I would've answered as well...LinusGeffarth

1 Answers

2
votes

What actions are you segueing on? You're performSegueWithIdentifier method shouldn't be calling itself, that is definitely why you are getting two back buttons. Do you have this hooked up in storyboards as well? You might not even need the performSegueWithIdentifier call at all if you have your segues set up in storyboard, and then you just prepareForSegue for each.