我在这里使用默认的Bar Button Item editButtonItem:
@property (nonatomic, assign) BOOL isEditing;
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
[self setupInterface];
}
- (void)setupInterface {
if (self.dataElement) {
self.isEditing = NO;
self.nameTextField.text = self.dataElement.name;;
} else {
self.isEditing = YES;
self.deleteButton.hidden = YES;
}
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
editing = self.isEditing;
[super setEditing:editing animated:YES];
if (editing) {
[self saveAction];
[self.navigationController popViewControllerAnimated:YES];
} else {
self.isEditing = !self.isEditing;
}
}
- (void)setIsEditing:(BOOL)isEditing {
_isEditing = isEditing;
if (isEditing) {
self.deleteButton.hidden = NO;
self.nameTextField.userInteractionEnabled = YES;
} else {
self.deleteButton.hidden = YES;
self.nameTextField.userInteractionEnabled = NO;
}
}
但是,它不会从“编辑”更改为“完成”按钮的标题。 我知道,它可以自动更改,并且不想分配它: self.editButtonItem.title = @"完成";
答案 0 :(得分:0)
将Select * from Course a join CourseProp b on a.courseId = b.courseId and b.prop1="demo"
按钮更改为完成按钮使用此功能,
navigationItem
将[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
按钮更改为修改按钮,请使用此
navigationItem
如果您已通过IB Storyboard添加了按钮,请确保设置标识符。然后在代码中添加以下内容:
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleBordered];
答案 1 :(得分:0)
试一下
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *leftLoginBar=[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(myProfileClickOnDashboard)];
leftLoginBar.tintColor=White;
self.tabBarController.navigationItem.leftBarButtonItem = leftLoginBar;
}
-(void)myProfileClickOnDashboard
{
UIBarButtonItem *rightLoginBar=[[UIBarButtonItem alloc]initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(filterClickOnDashboard)];
rightLoginBar.tintColor=White;
self.tabBarController.navigationItem.leftBarButtonItem = rightLoginBar;
//do ... when your bar button is Edit
}
-(void)filterClickOnDashboard
{
UIBarButtonItem *leftLoginBar=[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(myProfileClickOnDashboard)];
leftLoginBar.tintColor=White;
self.tabBarController.navigationItem.leftBarButtonItem = leftLoginBar;
//do... when bar button is Done.
}
答案 2 :(得分:0)
找到解决方案:我们只能使用 - (void)setEditing:(BOOL)编辑动画:(BOOL)动画方法。
对某人有用:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
[self setupInterface];
}
- (void)setupInterface {
if (self.dataElement) {
self.nameTextField.text = self.dataElement.name;
}
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:YES];
if (editing) {
self.deleteButton.hidden = (self.dataElement == nil);
self.addImageButton.hidden = NO;
self.nameTextField.userInteractionEnabled = YES;
} else {
self.deleteButton.hidden = YES;
self.addImageButton.hidden = YES;
self.nameTextField.userInteractionEnabled = NO;
[self saveAction];
}
}
现在一切正常。