有没有办法通过NSNotificationCenter调用关闭TabBarController及其所有childViewControllers的函数?
这不起作用:
@implementation TabBarC
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(signedOut) name:@"SignOut" object:nil];
}
- (void)signedOut
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"SignOut" object:nil];
[self.tabBarController dismissViewControllerAnimated:YES completion:nil]; // was hoping that this would close everything in 1 shot
}
这使应用程序崩溃了:
- (void)signedOut
{
NSLog(@"signedout from tabbar");
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"SignOut" object:nil];
for (int x = 0; x < self.childViewControllers.count; x++) {
[[self.childViewControllers objectAtIndex:x] removeFromSuperview];
}
[self.tabBarController dismissViewControllerAnimated:YES completion:nil];
}
使用控制台消息:
2015-04-28 17:37:03.815 AppName[65151:6525380] -[UINavigationController removeFromSuperview]: unrecognized selector sent to instance 0x7a7a8cb0
2015-04-28 17:37:03.823 AppName[65151:6525380] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController removeFromSuperview]: unrecognized selector sent to instance 0x7a7a8cb0'
我正在创建的是一个应用程序,其中包含许多嵌入在navigationControllers,ContainerViews和tapBarController中的ViewControllers / TableViewControllers。在用户点击其中一个ViewControllers中的Sign Out后,它应该将所有内容弹回到SignInViewController。
THX!