iOS-静态uitableViewCell-返回当前高度



我正在尝试使用static uitaiteViewController构建表单 - 我想实现iOS7揭示方法以显示Uipickerview/uidetyView inline,但是由于表是静态的,因此证明其有问题而不是动态。

无论如何 - 我在这个问题中遵循了Aaron Bratcher的解决方案-IOS 7-如何在表视图中显示到适当的日期选择器? -

看起来它非常适合 - 我唯一的问题是我的桌子单元格的高度变化 - 因此,我需要返回200个高度或零的日期选择器行 - 但是对于他们需要保持当前需要的所有其他一切身高 - 我不确定这是什么最好的编码方法 - 我需要参考当前的单元格,并且基本上要保持自己的状态,除非您是Pickerrow?

这就是我到目前为止得到的 -

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 5 && indexPath.row == 1) { // this is my picker cell
        if (_editingStartTime) {
            return 220;
        } else {
            return 0;
        }
    } else {
         UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        //return THE CURRENT CELLS HEIGHT
    }
}

不确定我如何访问上面的单元格高度 - 甚至该逻辑是否会在高度forrowatIndExpath中做我想做的事情?有什么想法吗?

欢呼

在静态表观视图中,您可以向超级询问故事板中存在的单元格的高度。

例如:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    /* ... */
    else {
        CGFloat height = [super tableView:tableView heightForRowAtIndexPath:indexPath];
        return height;
    }
}

对于其他数据源方法也是如此,因此您也可以从- tableView:numberOfRowsInSection:中删除一些代码。

UITableViewCell类是UIView的子类,因此它基本上是具有自己帧的视图。如果告诉您的表视图单元格,则应访问其框架属性:

return cell.frame.size.height;

但是,如果您希望该特定的单元格与其他单元格具有相同的高度,则应

return tableView.rowHeight;

正如左轮手枪所说。您可能已经从接口构建器设置了RowHeight属性,也可以在代码中明确设置它。

尝试

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 5 && indexPath.row == 1) { // this is my picker cell
    if (_editingStartTime) {
        return 220;
    } else {
        return 0;
    }
} else {
   return self.tableView.rowHeight;
}

}

最新更新