自定义UITableViewCell有时没有响应
我面临一个奇怪的问题。 我想显示一个自定义单元格而不突出显示它。 我的UITableViewCell
在我的表中有5个元素,如UILabel,UIImage等。问题是当我点击单元格时有时不会显示alertview。 这是我的didSelectRowAtIndexPath
的代码:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:LocalizedString(@"Please input") delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; return;
我正在做一个关于它的广泛研究。 首先,我改变了:
cell.selectionStyle = UITableViewCellSelectionStyleNone
至
cell.selectionStyle = UITableViewCellSelectionStyleDefault UIView *bgColorView = [[UIView alloc] init]; bgColorView.backgroundColor = [UIColor myCellColor]; [cell setSelectedBackgroundView:bgColorView];
由于我不想突出显示,我将单元格的高亮颜色设置为单元格背景颜色,但问题是,它也突出显示分隔符。 因此,当我点击分离器更改的颜色时,它看起来不太好。
我想知道如何在没有自定义单元格的情况下解决这个问题。
编辑说明:
始终调用didSelectRowAtIndexPath
但并不总是显示AlertView。
简单的UIAlertController或UIAlertView无关紧要。 两者有时都不会显示。
很可能你用一些UI组件覆盖整个单元格,所以你不能真正触摸单元格来执行didSelectRowAtIndexPath
方法,请参阅下面的示例图片。
cell
的整个绿色部分是uibutton
:
因此,这不会在每次单元格上检测到您的触摸并正确执行didSelectRowAtIndexPath
方法。
希望这可以帮助。
检查您的委托方法。 自动填充有时可能很有趣并插入didDeselectRowAtIndexPath而不是didSelectRowAtIndexPath