關於覆蓋導航控制器的後退按鈕動作有很多問題,但大家都知道沒有直接的方法來做到這一點。我通過繼承UINavigationController並重寫UINavigationBarDelegate方法來實現此目的。但問題是,UINavigationController的接口沒有實現UINavigationBarDelegate協議(但是它實現了這個方法,因爲這個代碼工作:),並且我擔心這個應用程序會被Apple拒絕,因爲這裏使用的是未公開的API。捕捉UINavigationController的本機後退按鈕動作
所以,問題是:你認爲,它是私人API使用或不?代碼如下:
@interface CustomNavigationController : UINavigationController <UINavigationBarDelegate>
@end
@implementation CustomNavigationController
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {
BOOL shouldPop = [[self topViewController] enableBackButton]; // every view controller overrides this method to disable or enable pop of view controller
if (shouldPop) {
//here is the warning about "UINavigationController may not respond to selector"
return [super navigationBar:navigationBar shouldPopItem:item];
} else {
return NO;
}
}
@end
這是UINavigationBarDelegate的協議方法:[super navigationBar:navigationBar shouldPopItem:item]; UINavigationController不實現UINavigationBarDelegate協議。 – Mitya