简体   繁体   English

iOS UITableView-向左滑动并单击单元格均显示删除按钮

[英]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.. 试试这个方法。

  • When deleting a row you must remove that data form your 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.

相关问题 当我滑动单元格时,iOS UITableView默认滑动删除按钮不显示 - iOS UITableView Default swipe delete button not showing when i swipe the cell iOS在UITableView上从左滑动,同时保持滑动以删除 - iOS swipe from left on UITableView while remaining Swipe to delete 如何在类似于 iOS 邮件的 UITableView Cell 中实现从左到右滑动 - How to Implement Swipe Left to Right in UITableView Cell similar to iOS Mail 有没有办法在iOS 7中的iOS 6之类的表格视图调用中向左和向右滑动以显示删除按钮。 - Is there any way to show delete button on Swipe left and Right on tableview call like iOS 6 in iOS 7. iOS7 UITableView滑动以删除并触摸以隐藏删除按钮 - iOS7 UITableView swipe to delete and touch to hide delete button 向左滑动以删除单元格在ios 8中无法正常工作但在ios 7中有效 - Swipe left to delete cell does not work properly in ios 8 but works in ios 7 在UITableViewCell中向左或向右滑动以删除没有删除按钮的单元格? - Swipe left or right anywhere in a UITableViewCell to delete the cell with no delete button? UITableview-滑动删除有时会导致点击单元格中的按钮 - UITableview - swipe to delete sometimes causes a button in the cell to be tapped 当我在单元格上从右向左滑动时,UITableviewcell删除按钮会增加 - UITableviewcell delete button apprearing when I swipe right to left on a cell 向上滑动以在UITableView中显示按钮吗? - Swipe up to show button in UITableView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM