Note that there are some explanatory texts on larger screens.

plurals
  1. POMake a custom back button for UINavigationController
    primarykey
    data
    text
    <p>I'm developping an app for iOS 4.2+. I subclassed my <code>UINavigationController</code> to insert two <code>UIImageView</code> and make the navigation bar look custom. Everything is working great but I have a little problem. I created custom <code>UIBarButtonItem</code> and inside my view controllers i put them with :</p> <pre><code>self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backButton]; </code></pre> <p>It works too but the problem is that to make this work I need to call it from:</p> <pre><code> - (void)viewDidAppear:(BOOL)animated ; </code></pre> <p>So it only appears after the animation and I can see the non customized button 1 second before the customized one replace it.</p> <p>(I tried with <code>viewWillAppear</code> but then nothing append in navigationbar)</p> <p>I would like to know if you have a solution that could correct this problem.</p> <p>PS: I never use IB, everything is made programmatically.</p> <p>Thanks from France !</p> <p>EDIT 1: here is the code that didn't show anything for <code>viewWillAppear</code>:</p> <pre><code>- (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]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload