user6631314
user6631314

Reputation: 1964

IOS/Objective-C/Storyboard: Detect when show segue underway

I am using a standard "show" segue in storyboard for a transition between two view controllers.

In the second VC, there is a method in viewWillAppear that fires a progress bar that is appearing during the segue and marring its appearance.

Is there any way to detect that the segue is in progress so that I can delay the progress bar until after the segue is complete?

I know I could move the progress bar to a later point in the lifecycle of the second view controller such as viewDidAppear but in most cases, the VC is reached without this particular segue and I would like the progress bar to fire immediately. If in the midst of the segue, however, I'd like to delay it.

Note: these are garden variety show Segues with animation in Storyboard, not custom segues.

Upvotes: 0

Views: 50

Answers (1)

Reza Dehnavi
Reza Dehnavi

Reputation: 2273

You can define a public method for fire the progress bar and call it from first VC. Here is the implementation of this approach:

In FirstVC.m:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // set segu identifier to SecondVC in StoryBoard        
    if ([segue.identifier isEqualToString:@"SecondVC"]) {
            SecondVC *secondVC = (SecondVC *)segue.destinationViewController;
            [secondVC fireProgressBar];
    }
}

In SecondVC.h:

#import <UIKit/UIKit.h>

@interface SecondVC : UIViewController
  -(void)fireProgressBar;
@end

In SecondVC.m:

#import "SecondVC.h"

@implementation SecondVC

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(void)fireProgressBar {
    NSLog(@"Progress Bar Fired!!!");
}

@end

Upvotes: 1

Related Questions