8

この問題に対してすべてのスタックオーバーフローソリューションを試した後でも、まだイライラするほどうまくいきません。

//UIBarButtonItem declaration
UIBarButtonItem* button1 = [[UIBarButtonItem alloc] initWithTitle:@"Button Text" 
style:UIBarButtonItemStyleBordered target:self action:@selector(myAction)];

//method 1
[self setToolbarItems:[NSArray arrayWithObjects: button1, nil] animated:YES];

//method 2
[self.navigationController.toolbar setItems:[NSArray arrayWithObject:button1]];

//method 3
self.navigationController.toolbarItems = [NSArray arrayWithObject:button1];

//displaying toolbar
[self.navigationController setToolbarHidden:NO];

上記の方法はどれも、ツールバーにボタンを表示するために機能しません - 私が得るのは空のツールバーだけです。ここで私が見逃している明らかなものはありますか?

4

4 に答える 4

5

動く

//UIBarButtonItem declaration
UIBarButtonItem* button1 = [[UIBarButtonItem alloc] initWithTitle:@"Button Text" 
style:UIBarButtonItemStyleBordered target:self action:@selector(myAction)];

//method 1
[self setToolbarItems:[NSArray arrayWithObjects: button1, nil] animated:YES];

//displaying toolbar
[self.navigationController setToolbarHidden:NO];

ここまでviewDidAppear:(BOOL)animatedが、UINavigationController が管理する UIViewController のツールバー項目を取得するポイントです。

于 2013-09-13T08:51:43.153 に答える
3

使用する

self.toolbarItems=[NSArray arrayWithObject:button1]
于 2013-09-13T08:09:05.787 に答える