[英]iOS UITableView - Show delete button upon both swipe left and click cell
I have a UITableView
and also implemented the logic to swipe to show the delete button, as such: 我有一个UITableView
并且还实现了滑动显示删除按钮的逻辑,如下所示:
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
-(void)tableView:(UITableView *)tableViefw commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete {
//logic to delete...
}
}
However, I need a way for the delete button to also show up when the user clicks on a table cell. 但是,我需要一种方法来使删除按钮在用户单击表格单元格时也显示出来。 Is that possible? 那可能吗?
I've seen other answers that suggest using [tableView setEditing: true]
, but that also shows the red icon on the left and I don't want that. 我看过其他建议使用[tableView setEditing: true]
答案,但是它还在左侧显示红色图标,我不想要那样。
Thanks. 谢谢。
If you subclass UITabeViewCell
, then you can use the didSelectRowAtIndexPath:
method to get the clicked cell, you can then show a delete button (whatever design you want), and when that is clicked the cell gets deleted front the datasource and the tableView gets updated, whether there is a framework way of doing it, I do not know. 如果您将UITabeViewCell
子类UITabeViewCell
,则可以使用didSelectRowAtIndexPath:
方法来获取被单击的单元格,然后可以显示一个删除按钮(无论您要使用UITabeViewCell
设计),当单击该单元格时,该单元格都将在数据源的前面删除,并且tableView会被更新。 ,是否有执行此操作的框架方法,我不知道。
But good luck anyway :) 但是无论如何,祝你好运:)
Try this method.. 试试这个方法。
array
. 删除行时,必须从array
删除该数据。 After that you need to reload tableview
again to show the updated tableview
之后,您需要再次重新加载tableview
以显示更新的tableview
- (void)viewDidLoad
{
Your_tableview.editing=YES;
[super viewDidLoad];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(editingStyle == UITableViewCellEditingStyleDelete)
{
NSLog(@"Delete Success");
[Your_Array removeObjectAtIndex:indexPath.row];
[self.Your_tableView reloadData]
}
else
{
NSLog(@"Delete Canceled");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.