开发者

Dismiss ModalView does not work here

So I have a tabBarController as a modalview, and it shows up fine. As I click some of the tabs, the views are loading properly. I want to dismiss the modalView when I click on tabBarController.selectedIndex ==4

So I write in the viewDidLoad and also tried in the viewWillAppear of that view controller to dismissModalViewController and it does not work.

I tried

[s开发者_如何学运维elf.parentViewController dismissModalViewControllerAnimated:YES];

      // ... And also //

[self dismissModalViewControllerAnimated:YES];

Could someone point out why it does not work ?


All you have to do is pass a reference to the modally presented VC pointing on the VC that will present it modally.

Define a weak reference as a property in the UITabBarController subclass, and send a message to dismiss it when required.

For example using a property named mainViewController :

MySubclass *tbController = [[MySubclass ....];
tbController.mainViewController = self;
[self presentModalViewController:tbController animated:YES];

Then in MySubclass define

@property(assign) UIViewController *mainViewController;

and synthesize it, then when the tab you want gets selected :

[self.mainViewController dismissModalViewControllerAnimated:YES];


I think the 4th view controller (of the tab bar controller) is trying to get dismissed by the line

[self.parentViewController dismissModalViewControllerAnimated:YES];

Since this 4th view controller was not presented by any controller, this wont work.

And it is dismissing it's modal view controller by the line

[self dismissModalViewControllerAnimated:YES];

Since, this 4th view controller did not presented any view controller, this again should not work.

You want to dismiss the tab bar controller and not its 4th view controller.

Basically, you can get the reference of tab bar controller from the 4th view controller. As, [yourFourthViewController.tabBarController.parentViewController dismissModalViewControllerAnimated:YES];

I am guessing this without actually trying. Let me know if this works.


If you have the UINavigationController as the parent controller then the following line will work for you.

[self dismissModalViewControllerAnimated:YES];

But here I think you have the UIViewController is the parent controller instead of the UINavigationController. So, You can do one thing when presentModalViewController.

if(objView == nil)
    objView = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil];

UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:objView];

[self presentModalViewController:navigationController1 animated:YES];

Let me know if you need more help or any questions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜