How to provide an custom delete button in the swipe-to-delete gesture of UITableView?
I've implemented that default swipe-to-delete gesture in UITableView, and now I feel开发者_开发知识库 that this default button actually doesn't look good in the context. Also, it seems to not be localized. In french it still shows "delete" as text.
How can I provide a custom button here? This is how I implemented that guy:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// do stuff, a lot of stuff...really a lot...
}
You want tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:
in the UITableViewDelegate protocol.
Make a custom cell class and include:
- (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:@"delete.png"]];
[[subview.subviews objectAtIndex:0] addSubview:deleteBtn];
[deleteBtn release];
}
}
}
}
where @"delete.png" is your delete image
精彩评论