2 bluetooth99 bluetooth99 于 2012.11.29 15:44 提问

RightBarButtonItem的问题

在NavigationBar 中有一个编辑按钮Edit Button,点击跳转“done”。把Edit和Done变为大写字母,有人知道怎么实现吗?谢谢

self.navigationItem.rightBarButtonItem = self.editButtonItem;

3个回答

abcdeFGh_xyz
abcdeFGh_xyz   2012.11.29 17:02
已采纳

.h文件中创建UIBarButtonItembtnEdit对象:

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"];   
    }
}
love_loveec
love_loveec   2012.11.29 17:26
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
{
    ……
}
cai610182473
cai610182473   2014.02.27 17:53

self.navigationItem.leftBarButtonItem = self.editButtonItem;

点击显示Done,

Csdn user default icon
上传中...
上传图片
插入图片