Dismiss Modal View from uitabbarController view

こ雲淡風輕ζ 提交于 2019-12-10 11:52:28

问题


I presented a modal view where the presented view contains a tabbar controller.The view is displayed correctly,but when I add the dismissModalViewController to a button in tabbar viewController,it is not dismissing.Nothing is happening to the view.

How could I dismiss that modal view Controller?


回答1:


The presenting view controller should be the one handling the dismissal of the modal view controller as well. You should use a delegate to notify the presenting view controller that it can dismiss the view controller it presented:

In the modal view controller:

@protocol SomeProtocol<NSObject>
- (void)didFinishDoingWhatItNeedsToDo:(id)sender;
@end

@interface ModalViewController : UIViewController
@property (nonatomic, weak) id <SomeProtocol> delegate;
@end

@implementation

- (IBAction)buttonClicked:(id)sender {

    [self.delegate didFinishDoingWhatItNeedsToDo:self];

}

Then in the presenting view controller:

@interface SomeObject : UIViewController <SomeDelegate>
@end

@implementation

- (void)someMethod {

    ModalViewController *mvc = [[ModalViewController alloc] init];
    mvc.delegate = self;

    [self presentViewController:mvc animated:YES completion:nil];
}

- (void)didFinishDoingWhatItNeedsToDo:(id)sender {

    [self dismissViewControllerAnimated:YES completion:nil];
}



回答2:


when you were presenting the controller with tabbar, you must have used :

[self presentModalViewController:newTabBarController animated:YES];

so when you want to dimiss you have to say,

[self.tabBarController dismissModalViewControllerAnimated:YES]



回答3:


[[self parentViewController] dismissModalViewControllerAnimated:YES];


来源:https://stackoverflow.com/questions/10944687/dismiss-modal-view-from-uitabbarcontroller-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!