作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试调试新应用程序的问题,但有些地方不对劲。在应用程序中,我通过将 2 个 UILabel 和 1 个 UIImageView 直接添加到 cell.contentView 来设置自定义 UITableViewCells
在我的应用程序中,某些表格 View 单元格不可选择(它们不响应点击事件)。屏幕上的第二个单元格始终无法选择,然后随机其他单元格也无法选择。
在我的调试工作中,我将所有内容都剥离了以下代码的基本要素:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ReviewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = @"foo";
return cell;
}
即使这是通用的样板代码,看起来如下所示:
并非所有单元格都是可选的。
我错过了什么?
更新
如有兴趣,这里更新了我的行选择代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ReviewWebViewController *rvc = [[ReviewWebViewController alloc] initWithReview:[self.reviews objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:rvc animated:YES];
[rvc release], rvc=nil;
}
最佳答案
很多事情已经提到了,我不会重复。
但是请确保您添加到 UITableViewCell 的元素的 userInteractionEnabled
设置为 NO
。尤其是在不使用 IB 时,切勿对默认值做出过多假设。
关于iphone - UITableViewCell 并不总是可选择的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4676239/
我是一名优秀的程序员,十分优秀!