UIToolBar items added during loadView not appearing
I have a UIViewController which is created programmatically. I include the following code in loadView. The toolbar is shown, but not the button I ad开发者_运维技巧ded. Any help would be appreciated please.
[self.navigationController setToolbarHidden:NO animated:NO];
UIBarButtonItem *actionB = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(actionBTapped:)];
[self.navigationController.toolbar setItems:[NSArray arrayWithObject:actionB] animated:NO];
[actionB release];
You want to set the items on the UIViewController itself, not its navigation controller:
self.toolbarItems = [NSArray arrayWithObject:actionB];
Try this:
NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease];
UIBarButtonItem *labelButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil] autorelease];
[items addObject:labelButton];
[items addObject:[[[UIBarButtonItem alloc] initWithTitle:@"YoutTitle" style:UIBarButtonItemStyleDone target:self action:@selector(actionBTapped:)] autorelease]];
[self.navigationController.toolbar setItems:items animated:NO];
精彩评论