문제

I am working on a project where I am calling several segues instead of using Navigation Controllers. Earlier in my project, I setup a modal segue, and called it from within the IBAction method of several different buttons (I call the same segue from different buttons as I am passing a string along with the segue).

In my storyboard it looks like this:

UIButton with linked IBAction

Modal Segue with Custom Identifier

Then in my code, I do this:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSLog(@"Vimeo Segue");
    if([segue.identifier isEqualToString:@"playVimeo"]) {
        WebViewViewController *controller = (WebViewViewController *)segue.destinationViewController;
        controller.vimeoURL = vimeoURL;
    }
}

- (IBAction)launchCreativeFuture:(id)sender {
    vimeoURL = @"72053500";
    [self performSegueWithIdentifier:@"playVimeo" sender:sender];
}

This works, and I'm happy with this. However...

I stumbled across another way of doing this, and I'm confused as to why they both work, and which one is recommended.

Here, I've added a linked IBAction and a modal segue, as per these pictures:

linked IBAction

modal segue identifier

And my code looks like this:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if([segue.identifier isEqualToString:@"pushToGraduateCourses"]) {
        NSLog(@"Grad Segue");
        UIViewController *controller = (UIViewController *)segue.destinationViewController;
    }
}


- (IBAction)launchGraduate:(id)sender {
    NSLog(@"Grad Button");
    [self performSegueWithIdentifier:@"pushToGraduateCourses" sender:sender];
}

Pretty identical code-wise, as far as I can tell... except that when I do this, I get a warning: "Warning: Attempt to present on while a presentation is in progress!" ... when I look at my console, the "Grad Segue" is logged twice... which makes sense, but in my first example, "Vimeo Segue" is only ever logged once.

I guess what I am asking is a few questions:

a) can anyone spot the difference between the two methods? Because I can't.

b) does creating a segue from Interface Builder automatically call performSegueWithIdentifier from the button without having to programatically call that from the IBAction that is linked to that button ?

c) which way is recommended ?

Thanks in advance,

~ Jesse

도움이 되었습니까?

해결책

A. Yes

B. Yes, when you created a segue from the button, the button calls performSegueWithIdentifier.

C. In my opinion, you should do as much UI design in the storyboard as possible, only go to code if you need to update your UI based on something in code. Ex. If the user is an administrator in your app, you will want to segue to different settings page than a standard user.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top