从视图的UITabBarController解雇模式视图(Dismiss Modal View fr

2019-09-17 21:36发布

我提出在呈现视图包含的TabBar正确显示controller.The视图模式的看法,但是当我的TabBar的viewController的dismissModalViewController添加到一个按钮,它不dismissing.Nothing正在发生的事情的看法。

我怎么能关闭那些模式视图控制器?

Answer 1:

所述呈现视图控制器应该是一个处理模态视图控制器解雇为好。 你应该用一个委托,通知它可以关闭它呈现的视图控制器中呈现视图控制器:

在模态视图控制器:

@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];

}

然后,在所述呈现视图控制器:

@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];
}


Answer 2:

当你呈现与的TabBar控制器,您必须使用:

[self presentModalViewController:newTabBarController animated:YES];

所以,当你想dimiss你不得不说,

[self.tabBarController dismissModalViewControllerAnimated:YES]


Answer 3:

[[self parentViewController] dismissModalViewControllerAnimated:YES];


文章来源: Dismiss Modal View from uitabbarController view