3


「ビューコントローラ」の上のコードからボタンを追加しました。

@implementation HBViewController
.....
.....
.....

- (void)viewDidLoad
{
    [super viewDidLoad];
    okButton = [[UIBarButtonItem alloc] initWithTitle:@"Ok" style:UIBarButtonItemStyleBordered target:self action:@selector(okayButtonPressed)];

    [self.navigationItem setRightBarButtonItem:okButton animated:NO];

}

- (void) okayButtonPressed{
NSLog(@"you pressed ok");
}

...しかし、どうすればボタンを非表示にできますか?

4

3 に答える 3

2
            //to disable

        self.navigationItem.rightBarButtonItem.enabled = NO;

            //to hide - hide means setting nil will remove that button

        self.navigationItem.rightBarButtonItem = nil;


            //if u want to show again then create and assign new button again

        okButton = [[UIBarButtonItem alloc] initWithTitle:@"Ok" 

                  style:UIBarButtonItemStyleBordered

                  target:self action:@selector(okayButtonPressed)];

        [self.navigationItem setRightBarButtonItem:okButton animated:NO];
于 2012-05-23T11:11:25.847 に答える
1
self.navigationItem.rightBarButtonItem = nil;
于 2012-05-23T11:22:01.960 に答える
0

ゼロに設定するだけ

[self.navigationItem setLeftBarButtonItem:nil animated:YES];
于 2012-05-23T11:13:13.523 に答える