我正在为 iOS 4.2+ 开发一个应用程序。我将我的子类化为UINavigationController
插入两个UIImageView
并使导航栏看起来很自定义。一切都很好,但我有一个小问题。我创建了自定义UIBarButtonItem
并在我的视图控制器中放置了它们:
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backButton];
它也有效,但问题是要完成这项工作,我需要从以下位置调用它:
- (void)viewDidAppear:(BOOL)animated ;
所以它只出现在动画之后,我可以在自定义按钮替换它之前 1 秒看到非自定义按钮。
(我尝试过,viewWillAppear
但导航栏中没有附加任何内容)
我想知道您是否有可以解决此问题的解决方案。
PS:我从不使用 IB,一切都是以编程方式制作的。
来自法国的感谢!
编辑1:这是没有显示任何内容的代码viewWillAppear
:
- (void)viewWillAppear:(BOOL)animated {
[self setTitle:@"Jeu"];
//Bouton testflight
TIFButton *testFeedbackButton = [[TIFButton alloc]init];
[testFeedbackButton setTitle: @"Envoyer un Feedback" forState:UIControlStateNormal];
[testFeedbackButton addTarget:self action:@selector(launchFeedback) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *testFeedback = [[UIBarButtonItem alloc] initWithCustomView:testFeedbackButton];
self.navigationItem.rightBarButtonItem = testFeedback;
TIFBackButton *backButton = [[TIFBackButton alloc]init];
[backButton setTitle: @"Retour" forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(popToPrecedentViewController) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backButton];
}