gpt4 book ai didi

iPhone,如何将表格的“编辑”按钮切换到“完成”,然后再切换回“编辑”?

转载 作者:行者123 更新时间:2023-12-03 18:37:04 32 4
gpt4 key购买 nike

我添加了编辑按钮

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self
action:@selector(editNavButtonPressed)] autorelease];

但我似乎无法将其转到“完成”并返回,控制台显示其为 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],它将正确地从“编辑”/“完成”切换状态,并且还将在UIViewController本身上切换编辑模式。

设置如下:

-(void)viewDidLoad {
self.navigationItem.rightBarButtonItem = [self editButtonItem];
}

然后,您可以覆盖-[UIViewController setEditing:animated:],以便在切换编辑模式时立即收到通知。

-(void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
// Add your custom code here
}

或者您可以查询 UIViewController 的当前编辑状态,如下所示:

if ([self isEditing]) {
// Do something editing like
} else {
// Do whatever is not editing like.
}

关于iPhone,如何将表格的“编辑”按钮切换到“完成”,然后再切换回“编辑”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3872127/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com