简体   繁体   中英

Trying to dismiss presentingViewController using button in the subview

Basically I have two xibs, the first one is the main xib that contains a button that triggers an IBAction that calls:

UIViewController *overlaywindow = [[UIViewController alloc] initWithNibName:@"NewInvenView" bundle:nil];
overlaywindow.modalPresentationStyle = UIModalPresentationFormSheet;
overlaywindow.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentViewController:overlaywindow animated:YES completion:nil];

This produces the result I want.

However, in NewInvenView.xib I'm trying to create a button that will dismiss itself (and close the PresentingView). I link the button with the NewInvenViewController.h and implements the method in NewInvenViewController.m. But when I run it, it doesn't work.

Whenever the button is triggered, the function is called but I get an error:

2012-12-24 20:33:50.984 Dokodemo[1467:907] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController filterstock:]: unrecognized selector sent to instance 0x21033990'...

I think it's also important to note that, I get an error regardless of what is inside the function implementation. Even when the function does nothing

why is this?

If you Do the flip Animation with navigationController it will be Easy.

 -(void)goToNextView:(id)sender{

          NextView *info3 = [[NextView alloc]initWithNibName:@"NextView" bundle:nil];
            UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:info3];

            info3.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            [self.navigationController presentModalViewController:nvc animated:YES];

        }

// if you using latest Version of iOS Just Change the following

[self.navigationController presentViewController:nvc animated:YES completion:nil];

in your Second view Controller You can use this to Dismiss.

-(IBAction)goToPrevious:(id)sender

{

[self.navigationController dismissModalViewControllerAnimated:YES];

// For latest Version

// [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

I believe that the problem is related to the nib file. If you check the error message, it says -[UIViewController filterstock:]: , which means that the message is sent to an object of UIViewController not NewInvenViewController .

Make sure that you set the class properly from the nib file, from the inspector pane.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM