Disabling two modal controllers

I found a few questions about this, but the answers do not solve my problem.

I have two controllers that I presented using presentModalViewController.

I added modalTransitionStyle to the first controller, which is called by the main controller. The first controller usually represented the second controller (without a transition style).

FirstVC *first = [[FirstVC alloc] initWithNibName:@"FirstVC" bundle:nil]; first.modalTransitionStyle = UIModalTransitionStylePartialCurl; [self presentModalViewController:first animated:YES]; SecondVC *second = [[SecondVC alloc] initWithNibName:@"SecondVC" bundle:nil]; [self presentModalViewController:second animated:YES]; 

This is the code I used to go to MainVC:

 [self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES]; 

And here is what happened:

enter image description here

The page did not expand. What is the reason I come across this?

+6
source share
6 answers

In my experiments, it seems that you cannot have a standard presentation (cover the vertical) after a partial curl and simultaneously release both of them, unless you are firing with an animation set to NO.

The way to fix this, however, is to reject secondVC without animation (this code is in the secondVC):

 -(IBAction)dismissSelf:(id)sender { [self dismissViewControllerAnimated:NO completion:nil]; } 

Then, in firstVC, release the viewDidAppear with the animation again, after checking that the controller is not displayed:

 -(void)viewDidAppear:(BOOL)animated { if (![self isBeingPresented]) { [self dismissViewControllerAnimated:YES completion:nil]; } } 

While the above code works to return to the initial controller view, you will see that the firstVC window appears before calling curl. If you don't want to see this, then the only way I could find to fix this was to create a secondVC image, add this as (as an image) a subview in firstVC before you fired secondVC. Thus, for this you need to use the code in secondVC (note that you need to connect to QuartzCore and import it into secondVC for this):

 -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; UIImage *img = [self imageWithView:self.view]; FirstViewController *first = (FirstViewController *)self.presentingViewController; UIImageView *iv = [[UIImageView alloc] initWithFrame:first.view.bounds]; iv.image = img; [first.view addSubview:iv]; } -(IBAction)dismissSelf:(id)sender { [self dismissViewControllerAnimated:NO completion:nil]; } - (UIImage *)imageWithView:(UIView *)view { UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, [[UIScreen mainScreen] scale]); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; } 
+6
source

You must submit your two submissions one by one using this call:

 [self presentViewController:firstViewController animated:YES completion:^( [self presentViewController:secondViewController animated:YES completion:^( }]; }]; 

it should behave better. Also, be aware that after that you will have to turn off both of these monitors.

 [self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:^{ [self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:^{ }]; }]; 
+3
source

It looks like you are firing the "first" without letting go of the "second".

Apple recommended way to do this with delegation.

Try making mainVC a delegate from 'first', to first call the mainVC method to hide yourself. Do this by declaring the "delegate" property "first" and setting it to mainVC when "first" is created. then define the firstDelegate protocol in first.h, which includes some function such as "removeFirst", and then imports first.h into mainVC. now execute the deleteFirst function in mainVC to actually drop the β€œfirst” and do whatever you need, which is displayed first.

gasp ... now make the "first" delegate of the "second" in the same way, and just make the function "offSecond" call the function "offFirst" mainVC, and everything will be right with the world.

I know this is a little trickier, but delegation is the basic concept of iOS, and this is a typical example of where it is used.

Here is a good explanation of how this works. http://chrisrisner.com/31-Days-of-iOS--Day-6%E2%80%93The-Delegate-Pattern

And I wish you good luck in your endless quest to understand the internal frauds of the skills of an Apple engineer, also known as Obj-C.

+2
source

I also had the same doubts. I decided in a different way -

Step 1: In the global class (singleton), you can define a variable flag.

 @property (nonatomic) int flag; 

Step 2: suppose you need to reject the second view controller and the first view controller and return to the Main view controller , and when you turn off the second Main view controller , you can set this value as supposedly 1 .

 [[Global sharedObject] setFlag:1]; [self.navigationController popViewControllerAnimated:YES]; 

Step 3: In - (void)viewWillAppear:(BOOL)animated method - (void)viewWillAppear:(BOOL)animated method you can set this method -

 if([[Global sharedObject] flag] == 1) { [[Global sharedObject] setFlag:0]; [self performSelector:@selector(back) withObject:nil afterDelay:0.5]; } - (void) back { [self.navigationController popViewControllerAnimated:YES]; } 

I hope your answer will be resolved with this. If you still have doubts, you can ask. Greetings :)

0
source
 - (UIViewController*)topViewController { UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController; while (topController.presentedViewController) { topController = topController.presentedViewController; } return topController; } - (void)dismissAllModalController{ __block UIViewController *topController = [self topViewController]; while (topController.presentingViewController) { [topController dismissViewControllerAnimated:NO completion:^{ }]; topController = [self topViewController]; } } 

Happy coding :)

0
source

You need to use unwind segue . Create an "empty" IBAction in the view controller that you want to move to.

 @IBAction func unwindToController(segue: UIStoryboardSegue) { } 

Then go to your storyboard and select the controller from which you want to switch. In the icons at the top of the selected controller, the leftmost one should be a yellow circle with a small white square in the center, as well as the owner of the file. Ctrl-Drag to the "Exit" label of the view controller that you want to restore. The conclusion can be found at the bottom of the controller trees or on the Storyboard as a right red square image with a white square arrow to the right. A dialog box unwindToController , select the unwindToController action that you created.

A new message, "Unwind segue to Exit", will appear in your FROM controller. Double click on it and give it an identifier, for example. unwindIdentifier

Now that you want to unwind two controllers in the FROM controller, use:

 self.performSegueWithIdentifier("unwindIdentifier", sender:nil) 

This will skip the middle controller and go into the second, showing only the TO controller in the animation.

0
source

Source: https://habr.com/ru/post/952707/


All Articles