开发者

Dismiss ModalViewController from another viewController in subview

开发者 https://www.devze.com 2023-03-02 22:35 出处:网络
I\'ve got a view called A open with presentModalViewController Method, inside this view I loaded secondary view using:

I've got a view called A open with presentModalViewController Method, inside this view I loaded secondary view using:

new_view = [[new_websongs alloc] initWithNibName:@"new_websongs" bundle:nil]; [mysubview addSubview:new_view.view]; ok, to here it's ok but now I need to dismiss the first view "A" calling a method [self dismissModalViewControllerAnimated:YES] situated if first "A" viewController from secondary view controller (new_view) but not work! the code is:

self.Aviewcontroller = [[Aview alloc] init];
[Aviewcontroller dismissModalVie开发者_运维问答wControllerAnimated:YES];
[Aviewcontroller release];

Please help ME!!!! Thanks


Did u try [self.parentViewController dismissModalViewControllerAnimated:YES];


You have a logical problem. Start reading View Controller Programming Guide for iOS

The view controller that present an modal view controller must dismiss it or the modal view controller must dismiss it self


Totally agree with other answers; think logically about the order of view controller order and type. So think about which controllers are shown modally, and those shown via a navigation controller.

You can of course set a number of view controllers with:

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated

without animation, then when required call say:

- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated

to show a specified view controller further up your stack of view controllers.

Hope this helps think about what you need to do? It's often a good idea to think about the order and type of view controllers in your app's interface in a separate project - where you can try it out on the device itself.


try this it should work

    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];


This works if you are presenting a modal view from a UISplitViewController. It can also be applied in so many other ways...

First, create an instance in your .h file for your appDelegate, (AppDelegate_iPad *appDelegate) then put this in your viewDidLoad or comparable method:

ipadDelegate = (AppDelegate_iPad *)[[UIApplication sharedApplication] delegate];

Now, present the first modal view like this:

    YOURVC *vc = [[YOURVC alloc] initWithNibName:@"YOURVC" bundle:nil];
    [ipadDelegate.splitViewController presentModalViewController:vc animated:YES];
    [vc release];

Say you have a subview, like a UITableView, and want to dismiss the modal from the didSelectRowAtIndexPath. All you have to do to dismiss your modal with a subview is create another ipadDelegate instance inside your subview's .h (if needed), reference the [[UIApplication sharedApplication] delegate] again, and dismiss:

[ipadAppDelegate.splitViewController dismissModalViewControllerAnimated:YES];

Essentially, as long-winded as it may be, use your appDelegate's controller to present and dismiss the the modal if you need to maintain a persistent reference to the presentingViewController...because all the things above just don't work in my case.

If you're presenting with your ipadDelegate, make sure you check the mode of presentation in your MainWindow_iPad.xib. Your "Transition Style" should be "Cover Vertical" and "Presentation" should be "Current Context" or your modal may present behind other views.

0

精彩评论

暂无评论...
验证码 换一张
取 消