• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Adding toolbar items only works in viewWillAppear: (?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding toolbar items only works in viewWillAppear: (?)


  • Subject: Re: Adding toolbar items only works in viewWillAppear: (?)
  • From: David Rowland <email@hidden>
  • Date: Tue, 19 Mar 2013 20:28:29 -0700

viewWillAppear occurs every time the view reappears, which may be frequently and has nothing to do with the creation and initialization of the view. Each time it appears you are recreating the button and setting in self.prevButton, e.g. which will release the former button and install an identical one. So, no, this is not the recommended place to do this.

Why viewDidLoad fails isn't clear. Is it possible that the toolbar is hidden or behind some other view?


On Mar 19, 2013, at 6:48 PM, Koen van der Drift <email@hidden> wrote:

> I am programmatically adding some toolbar items to a view in a UIViewController subclass, and it only seems to work when I put the code in viewWillAppear:
>
> // add a toolbar with a prev and next button
>    self.navigationController.toolbarHidden = NO;
>    UIBarButtonItem *flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: self action: nil];
>    self.prevButton = [[UIBarButtonItem alloc] initWithTitle: @"Prev" style: UIBarButtonItemStyleBordered target: self action: nil];
>    self.nextButton = [[UIBarButtonItem alloc] initWithTitle: @"Next" style: UIBarButtonItemStyleBordered target: self action: nil];
>
>    self.toolbarItems = [NSArray arrayWithObjects: self.prevButton, flexibleItem, self.nextButton, nil];
>
> If I put it in viewDidLoad, the toolbar never shows up.  In the book by Conway and Hillegass (3rd ed), they put similar code in init, but that also doesn't work in my case. Interestingly, I am adding a UISearchBar in init, and that works just fine.
>
> Why is that? Is viewWillAppear the recommended place to do this?
>
> - Koen.
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Adding toolbar items only works in viewWillAppear: (?)
      • From: Koen van der Drift <email@hidden>
    • Re: Adding toolbar items only works in viewWillAppear: (?)
      • From: Koen van der Drift <email@hidden>
References: 
 >Adding toolbar items only works in viewWillAppear: (?) (From: Koen van der Drift <email@hidden>)

  • Prev by Date: Re: Global (all-user) preferences for an application
  • Next by Date: Re: Callbacks from async blocks
  • Previous by thread: Adding toolbar items only works in viewWillAppear: (?)
  • Next by thread: Re: Adding toolbar items only works in viewWillAppear: (?)
  • Index(es):
    • Date
    • Thread