从uitabbarController视图中关闭模态视图

时间:2012-06-08 07:27:53

标签: iphone objective-c uitabbarcontroller modalviewcontroller

我提出了一个模态视图,其中显示的视图包含一个tabbar控制器。视图显示正确,但是当我将dismissModalViewController添加到tabbar viewController中的按钮时,它不会被忽略。视图中没有任何内容。

我怎么能解雇那个模态视图控制器?

3 个答案:

答案 0 :(得分:2)

呈现视图控制器也应该是处理模态视图控制器的解雇的控制器。您应该使用委托来通知呈现视图控制器它可以解除它所呈现的视图控制器:

在模态视图控制器中:

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

答案 1 :(得分:0)

当您使用tabbar呈现控制器时,您必须使用:

[self presentModalViewController:newTabBarController animated:YES];

所以当你想要dimiss时,你必须说,

[self.tabBarController dismissModalViewControllerAnimated:YES]

答案 2 :(得分:0)

[[self parentViewController] dismissModalViewControllerAnimated:YES];