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 回答