Adding NavBar Button Programatically... But It Won't Show!
I'm adding a UIBarButtonItem
programatically, however the damned thing won't add itself to the navigation bar (which was added in IB). Here's the code I'm using to add it:
UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share)];
self.navigationItem.rightBarButtonItem = shareButton;
in my viewDidLoad
. Since I'm doing that programatically, does tha开发者_运维技巧t mean that the nav bar has to be done programatically as well? I can't think of any other reason as to why it won't add itself.
It may be a silly suggestion, but are you sure that your self.navigationItem IBOutlet is set in the NIB? i.e. maybe you are setting everything up OK in your NIB and it looks right, but if the outlet isn't connected you won't be able to use it.
精彩评论