非常琐碎的表视图:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 44;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SettingsCell"];
UILabel *label = (UILabel *)[cell viewWithTag:1];
switch (indexPath.row) {
case 0:
{
label.text = @"One";
break;
}
case 1:
{
label.text = @"Two";
break;
}
default:
break;
}
return cell;
}
当我点击一个单元格时,didSelectRowAtIndexPath不会被调用。
此外,单元格重叠:
这里会发生什么事?我可以滚动表格,但不能选择单元格。有一次,这件事起了作用,我搞不懂到底是怎么回事。
我使用的是一个原型单元格,在故事板中,选择被设置为“单一选择”。所有视图都有userInteractionEnabled = YES。
发布于 2014-10-22 14:25:09
这就是解决办法:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 44;
}
将返回类型从“浮动”更改为"CGFloat“。Xcode 6.1甚至没有将此标记为警告。
发布于 2014-10-22 14:05:43
在这里,你似乎反复提到第一个单元:
UILabel *label = (UILabel *)[cell viewWithTag:1];
这可能是文字被覆盖的原因。
试一试如下:
if(indexPath.row == 1)
{
cell.textLabel.text = @"One";
}
https://stackoverflow.com/questions/26517707
复制