我的NavigationBar上有一个简单的编辑按钮,一旦点击转到完成,我正在尝试将“编辑”和“完成”上的文本更改为大写文本,这可能吗?有人知道我可以查看的教程吗?
self.navigationItem.rightBarButtonItem = self.editButtonItem;
感谢。
答案 0 :(得分:1)
在.h文件中创建UIBarButtonItem
的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"];
}
}
答案 1 :(得分: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
}