我想在UITabbarViewController完全加载并显示在屏幕上时收到通知?
由于它继承自UIViewController,我尝试将委托设置为我的appdelegate并实现了viewDidAppear,但它永远不会被调用。
任何解决方案??
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.tabbar.delegate = self;
//other stuff
}
- (void)viewDidAppear:(BOOL)animated
{
NSLog(@"asdasd");
}
答案 0 :(得分:0)
我认为这不是一个非常优雅的解决方案,但您可以使用NSNotificationCenter
发布通知[[NSNotificationCenter defaultCenter] postNotificationName:myNotification object:self];
并按如下方式回复:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dosomething:) name:myNotification object:nil];
答案 1 :(得分:0)
设置UITabBarController的委托时,您只能覆盖UITabBarControllerDelegate方法而不能覆盖UITabBarController方法。
解决方案:A
从代码
创建UITabBarController解决方案:B
子类UITabBarController
对于这两种解决方案,您可以在viewDidLoad中进行编码,也可以使用视图已完全加载的信息发送NSNotification。
答案 2 :(得分:0)
使用从UIViewController继承的UITabBarController的viewDidAppear
。控制器负责视图的生命周期,而不是委托。