2

我的导航栏上有一个简单的编辑按钮,一旦点击变成完成,我正在尝试将“编辑”和“完成”上的文本更改为大写文本,这可能吗?有人知道我可以查看的教程吗?

self.navigationItem.rightBarButtonItem = self.editButtonItem;

谢谢。

4

2 回答 2

2

UIBarButtonItem在 .h 文件中创建 btnEdit 对象,如下所示:

UIBarButtonItem *btnEdit;

然后在.m文件中写下这段代码:

- (void)viewWillAppear:(BOOL)animated{
    btnEdit = [[UIBarButtonItem alloc]init];
    btnEdit.target = self;
    btnEdit.action = @selector(btnEdit_Click:);
    btnEdit.title = @"EDIT";
    self.navigationController.topViewController.navigationItem.rightBarButtonItem = btnEdit;
    btnEdit.enabled=TRUE;
 }

- (IBAction)btnEdit_Click:(id)sender
{
    if ([btnEdit.title isEqualToString:@"EDIT"]) 
    {
        [btnEdit setTitle:@"DONE"]; 
    }
    else 
    {
        [btnEdit setTitle:@"EDIT"];   
    }
}
于 2012-11-28T11:19:21.013 回答
0
UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithTitle: @"EDIT" style: UIBarButtonItemStyleBordered target: nil action: @selector(editPressed:self)];

[[self navigationItem] setRightBarButtonItem: newButton animated:NO];

newBackButton = nil;

进而:

- (void)editPressed:(id)sender
{
     // Your code
}
于 2012-11-28T11:12:07.653 回答