开发者

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜