我有一个UINavigationController
我UITableView
我正在使用editButtonItem
来编辑UITableView
。
以下是代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.editButtonItem.title = @"تحرير";
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
首次启动时,会根据需要显示编辑按钮标题。但是当我点击它时,表视图进入编辑模式并显示Done
。当我点按Done
时,标题会重置为默认Edit
。
我是否必须在每个切换中设置标题:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
或者有更好的方法吗?我还想在编辑模式下更改“完成”文本。
答案 0 :(得分:2)
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
答案 1 :(得分:0)
在.h文件中点击一个UIBarButtonItem
。
UIBarButtonItem *btnSave;
之后在.m文件中
-(void)viewWillAppear:(BOOL)animated
{
btnSave = [[UIBarButtonItem alloc]init];
btnSave.target = self;
btnSave.action = @selector(btnEdit_Click:);
btnSave.title = @"Edit";// here give title which you want...
self.navigationController.topViewController.navigationItem.rightBarButtonItem = btnSave;
}
-(IBAction)btnEdit_Click:(id)sender
{
if ([btnSave.title isEqualToString:@"Edit"]) {
///something do here and also change the title of button here
[btnSave setTitle:@"Save"];// just for an example
}
else {
///something do here and also change the title of button here
[btnSave setTitle:@"Edit"];//just for an example
}
}
我希望这可以帮助你...
:)