向左滑动以删除单元格在ios 8中无法正常工作,但在ios 7中可以正常工作
“滑动以删除表格单元格”无法正常工作。我必须快速多次刷卡才能让它工作。下面的代码在ios 7中工作。有人能告诉我需要做些什么才能让它在ios 8中顺利运行吗 @SimpleTableCell的实现向左滑动以删除单元格在ios 8中无法正常工作,但在ios 7中可以正常工作,ios,objective-c,ios7,ios8,Ios,Objective C,Ios7,Ios8,“滑动以删除表格单元格”无法正常工作。我必须快速多次刷卡才能让它工作。下面的代码在ios 7中工作。有人能告诉我需要做些什么才能让它在ios 8中顺利运行吗 @SimpleTableCell的实现 - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reu
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(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:@"deleteButton.png"]];
[[subview.subviews objectAtIndex:0] addSubview:deleteBtn];
}
}
}
}
@end
这应该是非常简单的(在iOS 8中对我来说效果很好…) 您只需确保UITableView具有以下功能:
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// YES - we do want to enable "swipe to delete" on this row.
return YES;
}
…还有这个
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Add some code to delete your row...
}
您的代码中有这两部分吗?我也有同样的问题。几个小时后,我终于意识到问题来自我的导航控制器,它包含一个滑动手势识别器 本机注释编辑功能使用滑动手势识别器,因此,如果您有任何手势识别器,请不要忘记添加此行以允许同时进行手势识别
- (BOOL)gestureRecognizer:(UIPanGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UISwipeGestureRecognizer *)otherGestureRecognizer { return YES; }
我真的希望它会有帮助,因为它让我发疯