xcode 自定义 UITableView 中的删除按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13669920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Customize the delete button in UITableView
提问by Spire
I have the functionality for "Swipe to delete" the TableViewCell
. I want to customize the Deletebutton.
我有“滑动删除”的功能TableViewCell
。我想自定义删除按钮。
Is this possible, and how to access the Deletebutton ?
这可能吗,以及如何访问“删除”按钮?
采纳答案by Manohar Perepa
This method will be called when user performs the swipe action
当用户执行滑动操作时将调用此方法
Just Place this in your CustomCell
只需将其放在您的 CustomCell 中
- (void)willTransitionToState:(UITableViewCellStateMask)state
{
[super willTransitionToState:state];
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask)
{
for (UIView *subview in self.subviews)
{
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"])
{
UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)];
[deleteBtn setImage:[UIImage imageNamed:@"arrow_left_s11.png"]];
[[subview.subviews objectAtIndex:0] addSubview:deleteBtn];
}
}
}
}
You should not try that, you are not supposed to alter Apple's default views .
您不应该尝试这样做,您不应该更改 Apple 的默认视图。
回答by Wubbe
If you only need to change the title of the button, you only need to add the titleForDeleteConfirmationButtonForRowAtIndexPath method.
如果只需要改变按钮的标题,只需要添加titleForDeleteConfirmationButtonForRowAtIndexPath方法即可。
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"NewButtonName";
}
回答by Kaushal Bisht
Try this:
尝试这个:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// Your Code
}
}