UITableView分隔符出现在单元格错误的高度

时间:2014-12-05 22:35:54

标签: ios objective-c uitableview uikit

我将heightForRowAtIndexPath委托返回值设置为100.0f 看起来除了第一个单元格之外,高度是有效的

enter image description here

但更糟糕的是,当我触摸细胞时,它具有正确的高度100.0f

enter image description here

代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // For user profile cell
    if (indexPath.section == 0 && indexPath.row == 0) {
        FSMeHeaderCell *cell = (FSMeHeaderCell *)[tableView dequeueReusableCellWithIdentifier:kHeaderCellIdentifier];
        if (!cell) {
            cell = [[FSMeHeaderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kHeaderCellIdentifier];
        }
    }
    else {
       // ...... another cell
    }

    // ......
    return cell;
}

我还使用UIKit附带的默认单元格对其进行了测试,但效果相同。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"defaultTestId";
    if (!cell) {
        cell = [UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"defaultTestId"];
    }
    cell.textLabel.text = @"test";

    return cell;
}

它的默认单元格,但仍有此问题。

更新

我尝试设置cell.frame的高度,奇怪的是,似乎解决这个问题。
但是,当我用

登录时
CGRect frame = cell.frame;
frame.size.height = 100.0f;
cell.frame = frame;

NSLog(@"cell frame: %@", NSStringFromCGRect(cell.frame));

它的高度仍为44.0f(默认值),不变。

我在stackoverflow中看到了很多这样的问题而没有回答
是什么让分隔线出现在错误的高度?

0 个答案:

没有答案