自定义UITableViewCell有时没有响应

时间:2016-09-09 08:19:15

标签: ios objective-c iphone xcode uitableview

我面临一个奇怪的问题。我想显示一个自定义单元格而不突出显示它。我的表中的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无关紧要。两者有时都不会显示。

2 个答案:

答案 0 :(得分:1)

很可能你用一些UI组件覆盖了整个单元格,因此你无法真正触摸单元格来执行didSelectRowAtIndexPath方法,请参阅下面的示例图片。

cell的整个绿色部分,并且uibutton为浅蓝色:

enter image description here

因此,这不会在每次单元格上检测到您的触摸并正确执行didSelectRowAtIndexPath方法。

希望这有帮助。

答案 1 :(得分:0)

检查您的委托方法。自动填充有时可能很有趣并插入didDeselectRowAtIndexPath而不是didSelectRowAtIndexPath