【发布时间】:2016-09-09 08:19:15
【问题描述】:
我遇到了一个奇怪的问题。我想显示一个自定义单元格而不突出显示它。我的表中的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 无关紧要。有时两者都不显示。
【问题讨论】:
-
尝试在主线程中显示
UIAlertView,你应该停止使用它,它已被弃用 -
如何检测到您的单元格上的触摸?使用 tableView 委托或其他东西?
-
我使用默认的 tableView 委托并使用 didSelectRowAtIndexPath
-
您的 alertview 代码是否总是被调用,只是有时不显示?如有必要,您可以使用 NSLog 进行测试。
-
didSelectRowAtIndexPath 总是被调用,但有时不显示 alertview。其实我放 alertview 只是为了向你展示,而不是 AlertView,我的主要代码有时不起作用。但同样对于 alertview 以及它并不总是显示。
标签: ios objective-c iphone xcode uitableview