回答

2

在主視圖控制器中實現協議UINavigationControllerDelegate和選擇器navigationController:didShowViewController:animated:您可以操縱導航控制器呈現的視圖控制器。 e.g:

@interface ViewController() <UINavigationControllerDelegate> 
@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.navigationController.delegate = self; 
} 

-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ 

    UIView *banner = [[UIView alloc] initWithFrame:CGRectMake(0, navigationController.navigationBar.frame.size.height + 10, 
                   viewController.view.bounds.size.width,30)]; 
    banner.backgroundColor = [UIColor blueColor]; 

    [viewController.view addSubview:banner]; 
} 

@end 

在這個例子中ViewController應呈現爲UINavigationController第一視圖控制器。

我上傳的例子在github

希望它可以幫助

+0

頂部小通知的意見這是否實現,可顯示所有viewControllers或只是在主要的viewController? – user2924482

+0

是的,所有的視圖控制器,我沒有更新答案 – frankfg