[英]Showing delete button on swipe uitableviewcell like favourites
I am using following code 我正在使用以下代码
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
}
}
-(void)swipePressed:(UISwipeGestureRecognizer *)gestureRecognizer
{
CGPoint p = [gestureRecognizer locationInView:self.myTable];
NSIndexPath *indexPath = [self.myTable indexPathForRowAtPoint:p];
if (indexPath == nil)
NSLog(@"long press on table view but not on a row");
else
{
[[self.myTable cellForRowAtIndexPath:indexPath] setEditingAccessoryType: UITableViewCellEditingStyleDelete];
}
}
the swipePressed is run but no Delete button shows up... 运行swipePressed但没有显示删除按钮...
You do not need to install a swipe gesture recognizer in order to implement the swipe-to-delete functionality of a UITableView. 您无需安装滑动手势识别器即可实现UITableView的滑动到删除功能。 This functionality is provided to you for free by the UITableView delegate. UITableView委托免费提供此功能。 That is also not the correct use of setEditingAccessoryType
. 这也不是setEditingAccessoryType
的正确使用。 Remove the swipe gesture recognizer and method completely, then implement the method: 完全删除滑动手势识别器和方法,然后实现该方法:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.