我有一个以编程方式创建的UIViewController。我在loadView中包含以下代码。显示工具栏,但不显示我添加的按钮。任何帮助将不胜感激。
[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];
答案 0 :(得分:3)
您想要在UIViewController本身而不是其导航控制器上设置项目:
self.toolbarItems = [NSArray arrayWithObject:actionB];
答案 1 :(得分:1)
试试这个:
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];