【发布时间】:2015-03-16 11:59:25
【问题描述】:
我在 UIView 子类中创建了一个按钮。我需要通过此按钮致电popViewControllerAnimated,但没有任何效果!而且我看不到 viewController 推回 rootViewController 。这是我的代码:
- (void)SomeFunction {
backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton showsTouchWhenHighlighted];
[backButton addTarget:self
action:@selector(backToMainMenu)
forControlEvents:UIControlEventTouchUpInside];
}
- (void)backToMainMenu {
[self.window.rootViewController.navigationController popViewControllerAnimated:YES];
NSLog(@"back");
}
我把代码改成这样:
UINavigationController *vc = self.window.rootViewController.navigationController;
[vc.navigationController popViewControllerAnimated:YES];
但是什么也没发生。
【问题讨论】:
-
请不要尝试以这种方式访问控制器。它打破了 MVC 的所有设计模式。视图永远不必了解控制器架构。将按钮的代码放入控制器中。
-
即使我尝试从 viewController 触发方法仍然没有任何反应
ContentViewController*vc; [vc backToMainMenu];@ryancrunchi -
为什么不用simple for popviewcontroller,[self.nagigationController popViewControllerAnimated:YES];
-
@virus 我告诉过这个方法在一个自定义类中,它是
UIView的子类 -
控制台中是否记录了任何错误,如果这有助于找出问题?
标签: ios objective-c iphone xcode