I am trying to implement swipe to delete in UITableView
. ViewController
does not contain pan gesture or any other function. The viewController
which contains UITableView
, is pushed when side menu is selected. Following is the code I used.
我试图在UITableView中实现滑动删除。 ViewController不包含平移手势或任何其他功能。当选择侧面菜单时,将推送包含UITableView的viewController。以下是我使用的代码。
- (void)viewDidLoad {
[super viewDidLoad];
self.tableViewRefresh.dataSource = self;
self.tableViewRefresh.delegate = self;
// Do any additional setup after loading the view.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"cell1";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 1.0f;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
When I swipe, Delete button does not appear. But, when I swipe it very fast, delete button appears. Any help will be appreciated.
当我滑动时,不会出现删除按钮。但是,当我快速滑动时,会出现删除按钮。任何帮助将不胜感激。
4 个解决方案
#1
1
I also faced same issue and fixed by disabling panMode of side menu. If you are using MFSideMenu have a look at bellow code-
我也面临同样的问题,并通过禁用侧面菜单的panMode来修复。如果您正在使用MFSideMenu,请查看以下代码 -
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:centerViewController
leftMenuViewController:leftViewController
rightMenuViewController:nil];
container.panMode = MFSideMenuPanModeNone;
#2
1
I assume that the default feature of tableview swipe delete is overridden by gesture recogniser used in same class or parent classes.Please check current class, parent class or libraries used in those classes.
我假设tableview swipe delete的默认功能被同一类或父类中使用的手势识别器覆盖。请检查当前类,父类或这些类中使用的库。
#3
0
Try this code. You can add n number of buttons as you want while swiping the uitableviewcell. Make sure you have return all the buttons in return statement (return @[deleteAction, someOtherButtonName])
试试这个代码。您可以在滑动uitableviewcell时根据需要添加n个按钮。确保返回return语句中的所有按钮(return @ [deleteAction,someOtherButtonName])
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
// Delete button
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
// Action for delete button
}];
deleteAction.backgroundColor = [UIColor redColor];
return @[deleteAction];
}
#4
0
Thank you all for your support.
谢谢大家的支持。
The issue has been fixed.
问题已得到解决。
I have been using LGMenuController class for implementing navigation drawer on App. The class uses gesture recognition functionality through out the app for show/close the side menu by the swipe gesture.
我一直在使用LGMenuController类在App上实现导航抽屉。该课程通过应用程序使用手势识别功能,通过滑动手势显示/关闭侧边菜单。
It seems that the default feature of table view's swipe delete is overridden by gesture recogniser used in LGMenuController class. Once the gesture recognition has disabled completely,then the swipe delete functionality of UITableView works fine.
似乎表格视图的滑动删除的默认功能被LGMenuController类中使用的手势识别器覆盖。一旦完全禁用手势识别,UITableView的滑动删除功能就可以正常工作。
#1
1
I also faced same issue and fixed by disabling panMode of side menu. If you are using MFSideMenu have a look at bellow code-
我也面临同样的问题,并通过禁用侧面菜单的panMode来修复。如果您正在使用MFSideMenu,请查看以下代码 -
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:centerViewController
leftMenuViewController:leftViewController
rightMenuViewController:nil];
container.panMode = MFSideMenuPanModeNone;
#2
1
I assume that the default feature of tableview swipe delete is overridden by gesture recogniser used in same class or parent classes.Please check current class, parent class or libraries used in those classes.
我假设tableview swipe delete的默认功能被同一类或父类中使用的手势识别器覆盖。请检查当前类,父类或这些类中使用的库。
#3
0
Try this code. You can add n number of buttons as you want while swiping the uitableviewcell. Make sure you have return all the buttons in return statement (return @[deleteAction, someOtherButtonName])
试试这个代码。您可以在滑动uitableviewcell时根据需要添加n个按钮。确保返回return语句中的所有按钮(return @ [deleteAction,someOtherButtonName])
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
// Delete button
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
// Action for delete button
}];
deleteAction.backgroundColor = [UIColor redColor];
return @[deleteAction];
}
#4
0
Thank you all for your support.
谢谢大家的支持。
The issue has been fixed.
问题已得到解决。
I have been using LGMenuController class for implementing navigation drawer on App. The class uses gesture recognition functionality through out the app for show/close the side menu by the swipe gesture.
我一直在使用LGMenuController类在App上实现导航抽屉。该课程通过应用程序使用手势识别功能,通过滑动手势显示/关闭侧边菜单。
It seems that the default feature of table view's swipe delete is overridden by gesture recogniser used in LGMenuController class. Once the gesture recognition has disabled completely,then the swipe delete functionality of UITableView works fine.
似乎表格视图的滑动删除的默认功能被LGMenuController类中使用的手势识别器覆盖。一旦完全禁用手势识别,UITableView的滑动删除功能就可以正常工作。