【发布时间】:2013-07-19 00:06:32
【问题描述】:
我已经看到了一些与此相关的问题,但没有一个可以帮助我解决此问题。
我有一个 MasterViewController -> AViewController -> BViewController
文档说:
呈现视图控制器负责关闭它呈现的视图控制器。但是,如果您在呈现的视图控制器本身上调用此方法,它会自动将消息转发到呈现的视图控制器。
[self.presentingViewController dismissModalViewControllerAnimated: YES];
从我的 B VC 调用这个方法,应该关闭我的 A 和 B VC。然而,它只会解雇孩子(B VC)。为什么?
- (IBAction)checkButton:(UIButton *)sender {
NSManagedObjectContext * context = [myAppDelegate managedObjectContext];
Work * newWork = [NSEntityDescription insertNewObjectForEntityForName:@"Work" inManagedObjectContext:context];
[newWork setName:_workName];
[myAppDelegate saveContext];
NSLog(@"%@", [self.presentingViewController description]);
[self.presentingViewController dismissModalViewControllerAnimated: YES];
}
我不知道这是否相关,但 A 和 B 风投是这样介绍的:
TWWorkNameViewController *controller = (TWWorkNameViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"WorkName"];
[self presentViewController:controller animated:YES completion:nil];
【问题讨论】:
-
不,它应该只关闭 BViewController。如果 A 展示了 B,那么写 [selfdismiss..](在 B 中)和 [self.presentingViewControllerdismiss..](也在 B 中)是相同的。
-
但是self.presentingViewController不应该是A VC吗?我从 B 获得了 A 的描述,我可以确认该方法是从 B 在 A 中调用的。我在这里缺少什么?
-
是的 self.presentingViewController 将是 A,并且由于 A 呈现了 B,A 正在解除它呈现的那个,即 B。当你在呈现的控制器中说 [self dismiss...] 时(B ),该消息被发送到控制器 A,它执行 [self dismiss...],但现在 self 是 A,因为它被转发了。
-
现在已修复。谢谢好心的先生,您非常清楚的解释并帮助我理解了这一点。 =)
标签: ios objective-c uiviewcontroller