当我使用heightForRowAtIndexPath时,UITableViewCell不会检测到tap:方法

时间:2015-09-28 17:12:45

标签: ios objective-c uitableview

我有UITableView个简单的UITableViewCell,其高度是在tableView: heightForRowAtIndexPath:方法中设置的。我在5个应用程序中使用这种方法,它每次都很完美,但是现在我遇到了一些问题,当我使用它时,我的单元格没有检测到水龙头。

正如我发现它在我在Xcode 6中创建的项目中完美运行,但它在我在Xcode 7中创建的项目中不起作用。有人知道会导致这个问题的原因吗? tableView: heightForRowAtIndexPath:方法有什么变化吗?它真的很烦人,因为我不知道,它在我的其他应用程序(使用Xcode6创建的项目)中仍能完美运行,但它不适合我刚刚创建的Xcode 7项目。当我删除它时,单元格开始再次检测到点击,当我添加它时,我甚至无法在NSLog中为单元格点击写出didSelectRowAtIndexPath:

如果有人能给我一些提示,我真的很感激。也许这只是我需要在IB中启用的基本功能,但无法弄明白。

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *) indexPath {

    if(!self.itemCell) {
        self.itemCell = [self.tableView dequeueReusableCellWithIdentifier:@"cell"];
    }

    NSString *object = [self.stringArray objectAtIndex:indexPath.row];

    self.itemCell.itemTitle.text = object;


    [self.itemCell layoutIfNeeded];

    CGFloat height = [self.itemCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;

    return height+5;
} 

(我也试过cell.userInteractionEnabled = YES;但没有成功。)

1 个答案:

答案 0 :(得分:0)

你可以通过删除所有的dequeing代码来尝试一次。我有一个这样的项目,它工作正常。

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *) indexPath {
NSString *object = [self.stringArray objectAtIndex:indexPath.row];

self.itemCell.itemTitle.text = object;


[self.itemCell layoutIfNeeded];

CGFloat height = [self.itemCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;

return height+5;
} 

希望这有帮助