iPhone,如何切换我的表格的编辑按钮,然后切换到完成并返回编辑? [英] iPhone, how do I toggle my Edit button for my table then to Done and back to Edit?
问题描述
我添加了我的编辑按钮
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self
action:@selector(editNavButtonPressed)] autorelease];
但我似乎无法将其转为完成并返回,控制台说它的Null
But I don't seem to be able to turn it to Done and back, the console says its Null
-(IBAction)editNavButtonPressed
{
//[self.tableView setEditing:YES animated:YES];
BOOL editing = !self.tableView.editing;
NSLog(@"tile=#%@#", self.navigationItem.rightBarButtonItem.title);
if ([self.navigationItem.rightBarButtonItem.title isEqualToString:NSLocalizedString(@"Edit", @"Edit")]) {
self.navigationItem.rightBarButtonItem.title = NSLocalizedString(@"Done", @"Done");
} else {
self.navigationItem.rightBarButtonItem.title = NSLocalizedString(@"Edit", @"Edit");
}
//self.navigationItem.rightBarButtonItem.enabled = !editing;
//self.navigationItem.rightBarButtonItem.title = (editing) ? NSLocalizedString(@"Done", @"Done") : NSLocalizedString(@"Edit", @"Edit");
[self.tableView setEditing: editing animated: YES];
}
推荐答案
您应该使用 - [UIViewController editButtonItem]
,它将正确地从编辑/完成切换状态,并且还将切换<$ c上的编辑模式$ c> UIViewController 本身。
You should use the -[UIViewController editButtonItem]
, it will correctly toggle state from Edit/Done, and will also toggle the editing mode on the UIViewController
itself.
设置如下:
-(void)viewDidLoad {
self.navigationItem.rightBarButtonItem = [self editButtonItem];
}
然后你可以覆盖 - [UIViewController setEditing:animated :]
在切换编辑模式时立即收到通知。
You can then override -[UIViewController setEditing:animated:]
to get notified immediately when the editing mode is toggled.
-(void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
// Add your custom code here
}
或者您可以查询 UIViewController
因为它的当前编辑状态如此:
Or you can query the UIViewController
for it's current editing state like so:
if ([self isEditing]) {
// Do something editing like
} else {
// Do whatever is not editing like.
}
这篇关于iPhone,如何切换我的表格的编辑按钮,然后切换到完成并返回编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!