Question

I am new to iOS development and I am doing little project as a research.

I have an app where after I start it I am showing MainViewController, but if this is the first launch of this app I want to show Sub1ViewController (names are made up) using presentViewController method called in MainViewController.

After user puts in some data on Sub1ViewController I invoke dismissViewController method to hide it.

The hard part starts here - I have no idea how to capture the event when Sub1ViewController is dismissed and I can present Sub2ViewController also using presentViewController invoked from MainViewController. All the time I am getting messages that I am trying to present view when another present or dismiss is in progress.

PS: I am using Xamarin, but I also understand objective-c.

Was it helpful?

Solution

hi you can try out this

  [self dismissViewControllerAnimated:YES completion:^{
    //code to be executed with the dismissal is completed
   // for example, presenting a vc or performing a segue
}];

you can write code after completion of dismiss one view controller

or You can achieve this by present view after some delay in dismiss method

-(void)onDismisViewController{

[self performSelector:@selector(presentSecoundViecontoller) withObject:self afterDelay:1];

}

-(void)presentSecoundViecontoller
{

SecoundViewController *secoundVC = [[SecoundViewController alloc]    initWithNibName:@"secoundVC" bundle:nil];
[self.navigationController presentViewController:secoundVC animated:YES completion:NULL];

}

EDIT

Try this i Try and it work

crate one delegate Method in subviewcontroller1 and set delegate in mainviewcontroller and implement method in mainvie and present subviewcontroller2 in this delegate method its work

try this if not let me know will post code.

Delegate Creation on subviewcontroller1.h file

@protocol st1Protocol <NSObject>
    - (void)presentViewController;
@end
@interface SubViewController1 : UIViewController
@property (nonatomic,assign) id <st1Protocol> delegate;
- (IBAction)dissmiss:(id)sender;

SubViewcontroller1.m file i put dismiss view on button click of subviewcontroller1 you do this in you dismiss method

 - (IBAction)dissmiss:(id)sender {
    [self dismissViewControllerAnimated:YES completion:^{
    //code to be executed with the dismissal is completed
    // for example, presenting a vc or performing a segue
       [self.delegate presentViewController];
}];
}

now implementation of this delegate method in main view controller. implement delegate method in .h file

    @interface StViewController : UIViewController<st1Protocol>

set delegate in mainviewcontroller.m file view didload

- (void)viewDidLoad
  {
      [super viewDidLoad];
      subViewcontroller1 *st1=[[subViewcontroller1  alloc]initWithNibName:@"subViewcontroller1" bundle:nil];
      st1.delegate=self;
      [self presentViewController:st1 animated:YES completion:nil];
  // Do any additional setup after loading the view from its nib.
 }

delegate method implementation in main view controller

 -(void)presentViewController{
     SubmViewcontroller2 *st2=[[SubmViewcontroller2 alloc]initWithNibName:@"St2ViewController" bundle:nil];
[self presentViewController:st2 animated:YES completion:nil];
}

hope this may help you happy coding.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top