我使用的代码我如何识别self.editButtonItem按钮的点击事件?
leftBarButton = self.editButtonItem;
我想改变一些禁用/相对于编辑按钮的点击动作使其他按钮的属性中设置的UINavigationController的我左边栏按钮的编辑按钮。
我怎样才能找到是否按下编辑按钮?
我使用的代码我如何识别self.editButtonItem按钮的点击事件?
leftBarButton = self.editButtonItem;
我想改变一些禁用/相对于编辑按钮的点击动作使其他按钮的属性中设置的UINavigationController的我左边栏按钮的编辑按钮。
我怎样才能找到是否按下编辑按钮?
编辑按钮的动作会向您的视图控制器发送setEditing:animated
消息。在您的子类中重写此操作以在进入或退出编辑模式时执行其他操作。
确保在最后调用super
实现来管理转换到编辑视图的其余部分。
UIBarButtonItem *barBut=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(doSomething)];
self.navigationItem.leftBarButtonItem=barBut;
[barBut release];
.h
-(void)doSomething;
.m
-(void)doSomething{
NSLog(@"dooooooooooooo");
//ur stuff
}
更新:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
将被称为
editButtonItem
Returns a bar button item that toggles its title and associated state between Edit and Done.
- (UIBarButtonItem *)editButtonItem
Discussion
If one of the custom views of the navigationItem property is set to the returned object, the associated navigation bar displays an Edit button if editing is NO and a Done button if editing is YES. The default button action invokes the setEditing:animated: method.
Availability
Available in iOS 2.0 and later.
See Also
@property editing
– setEditing:animated:
Declared In
UIViewController.h
谢谢维杰..但我想知道self.editButtonItem按钮的场景 – Confused
所以最后我得到了解决办法...
-(void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if(editing) {
//Do something for edit mode
}
else {
//Do something for non-edit mode
}
}
将调用此方法,但不更改self.editButtonItem
按钮的原始行为。
第二种方法不应该被使用。 –
在斯威夫特:
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
....
self.navigationItem.leftBarButtonItem = self.editButtonItem()
}
override func setEditing(editing: Bool, animated: Bool) {
// Toggles the edit button state
super.setEditing(editing, animated: animated)
// Toggles the actual editing actions appearing on a table view
tableView.setEditing(editing, animated: true)
}
在斯威夫特,你可以按照下面的方法:
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.rightBarButtonItem = editButtonItem()
}
override func setEditing(editing: Bool, animated: Bool){
super.setEditing(editing, animated: animated)
tableView.setEditing(editing, animated: true)
}
感谢您的信息...但是,如果我使用'setEditing:animated'方法,动画&红色减号按钮没有出现 – Confused
您必须在覆盖结束时调用'[super setEditing:editing animated:animated]'。 – jrturton
谢谢..它的工作原理... – Confused