2つの特定のビューコントローラーのビューが現在のビューの子孫であることを確認して、ボタンを非表示にする必要があります。これは、アプリがフォアグラウンドになったときに行われます。コード:
[[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 条件内に到達し、ボタンが非表示になっていることです。なぜですか?