问题描述
- RightBarButtonItem的问题
-
在NavigationBar 中有一个编辑按钮Edit Button,点击跳转“done”。把Edit和Done变为大写字母,有人知道怎么实现吗?谢谢self.navigationItem.rightBarButtonItem = self.editButtonItem;
解决方案
.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"];
}
}
解决方案二:
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
{
……
}
解决方案三:
self.navigationItem.leftBarButtonItem = self.editButtonItem;
点击显示Done,
时间: 2024-10-18 10:22:29