2011-02-07 23 views
0

我有一個UIViewController以編程方式創建。我在loadView中包含下面的代碼。顯示工具欄,但不是我添加的按鈕。任何幫助,將不勝感激請。UIToolBar在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]; 

回答

3

你想設置的UIViewController中本身的項目,而不是它的導航控制器:

self.toolbarItems = [NSArray arrayWithObject:actionB]; 
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];