开发者

Automatically dismiss underling modal view

开发者 https://www.devze.com 2023-04-08 05:53 出处:网络
I\'m sharing this as it took me A while to figure out. This is if you need to get rid of a double开发者_运维技巧 stack of modal views IF it is pressent.

I'm sharing this as it took me A while to figure out. This is if you need to get rid of a double开发者_运维技巧 stack of modal views IF it is pressent.

if(self.parentViewController.parentViewController)
        [self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];
else
    [self dismissModalViewControllerAnimated:YES];

I have a view that sometimes gets called from a modal view. In that case I would need to get rid of both views at the same time. While dealing with the situation where it was the only modal view. This worked.


As of xCode 4.2 this is no longer working, The new way to deal with this situation is:

if(self.presentingViewController.presentingViewController)
    [self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES];
else
    [self dismissModalViewControllerAnimated:YES];

As pointed out by @Hollance in a relevant thread of mine:

iOS 5 SDK treating UIViews differently

"There is a new property in iOS 5 named presentingViewController. The meaning of parentViewController got changed a bit with the new container view controller API, so it may not always be set when you think it is. That's what presentingViewController is now for."

0

精彩评论

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

关注公众号