从uitabbarController视图关闭模态视图 [英] Dismiss Modal View from uitabbarController view
问题描述
我呈现了一个模态视图,其中所呈现的视图包含一个标签栏控制器.该视图可以正确显示,但是当我将dismissModalViewController添加到标签栏viewController中的按钮时,它并没有关闭.该视图没有任何反应. > 我怎样才能解散该模式视图控制器?
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?
推荐答案
当前视图控制器也应该是处理模态视图控制器被解雇的控制器.您应该使用一个委托来通知呈现的视图控制器它可以关闭呈现的视图控制器:
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:
在模式视图控制器中:
@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];
}
这篇关于从uitabbarController视图关闭模态视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!