1

我确实有两个 ViewController 类,一个 firstviewController 另一个 secondViewController 在第一个 viewcontroller 我称之为[self dimissModalViewControllerAnimation:NO]; 关闭视图!现在我需要从另一个 secondViewController 类中删除相同的视图。

所以我需要打电话给超级!

[super dismissModalViewControllerAnimated:NO];

或者我是否需要创建任何协议来关闭视图!从另一个 secondViewController 类。

任何人都可以指导我解决这个问题。

4

2 回答 2

1

您应该只super在重载方法定义时使用,例如:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title = @"Login / Signup";
}

通常,如果您试图告诉一个视图从另一个视图做某事,委托是您的朋友。您可以创建一个弱delegate变量来保存对要关闭的视图控制器的引用,然后调用[delegate dismissModalViewControllerAnimated:NO];

于 2012-05-26T23:55:45.853 回答
1

您可以在 firstViewController 的 viewDidLoad 中注册通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"MyNotification" object:nil];

在 firstViewController 中添加事件处理程序

- (void)handleNotification:(NSNotification*)note {
    [self dismissModalViewControllerAnimated:NO];
}

然后就可以在 secondViewController 中触发事件了

[[NSNotificationCenter defaultCenter] postNotificationName:@"MyNotification" object:nil ];
于 2012-05-26T23:34:34.113 回答