我必须通过检查两个特定的viewcontroller隐藏按钮的视图是当前视图的后代。这是在应用程序到达前台时完成的。 代码:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil] ;
(void)applicationWillEnterForeground
{
if(!([hrViewController.view isDescendantOfView:self.view] || [reportViewController.view isDescendantOfView:self.view]))
{
[self.theFavouriteButton setHidden:YES];
}
}
问题是,尽管在前景中呈现的视图是hrViewController.view或reportViewController.view,但控件正在if条件内部并且隐藏了我的按钮。为什么会这样?