1

我呈现了一个模态视图,其中呈现的视图包含一个选项卡控制器。视图显示正确,但是当我将dismissModalViewController 添加到选项卡视图控制器中的按钮时,它没有被解散。视图没有发生任何事情。

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

4

3 回答 3

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];
}
于 2012-06-08T07:43:54.680 回答
0

当您使用标签栏呈现控制器时,您必须使用:

[self presentModalViewController:newTabBarController animated:YES];

所以当你想辞退时,你必须说,

[self.tabBarController dismissModalViewControllerAnimated:YES]
于 2012-06-08T07:32:26.083 回答
0
[[self parentViewController] dismissModalViewControllerAnimated:YES];
于 2012-06-08T07:35:37.850 回答