我想在UITableViewCellEditingStyleDelete
时更改按钮的颜色和文字,我该怎么做?以下是我如何调用删除单元格的方法:)谢谢!
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if(editingStyle == UITableViewCellEditingStyleDelete){
[self.tasks removeObjectAtIndex:indexPath.row];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:self.tasks forKey:@"tasks"];
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
[tableView endUpdates];
}
}
答案 0 :(得分:6)
您可以做的是:
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Set NSString for button display text here.
NSString *newTitle = @"Remove";
return newTitle;
}
完成此操作的方法调用可在Apple iOS Dev Docs here
中找到老实说,我不会改变颜色 - Apple HIG(人机界面指南)可能会建议颜色保持一致的红色,以确保用户对您应用的行为没有不同的期望。
答案 1 :(得分:0)
您可以自定义您的手机。然后,在方法cellforRowatindexPath上为此单元格添加UISwipeGestureRecognizer,如下所示:
//custom delete button on cell comment
UISwipeGestureRecognizer * swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(cellWasSwiped:)];
[swipeRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft |
UISwipeGestureRecognizerDirectionRight)];
[cell addGestureRecognizer:swipeRecognizer];
实施cellWasSwiped功能:
- (void)cellWasSwiped:(UISwipeGestureRecognizer *)recognizer {
//edit your custom button delete in here.
.....
[self.tableView commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:indexPath];
}