【发布时间】:2012-02-29 07:29:34
【问题描述】:
我需要有 2 种行。一个高度为 44 像素,另一个高度为 90 像素:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0)
return 90.0;
else
return 44.0;
}
问题是当我调用 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 因为我需要在 90px 的单元格中添加一个高度为 90px 但它被添加到单元格的中间而不是顶部。
if (indexPath.section == 0) {
cell = [tableView dequeueReusableCellWithIdentifier:ScrolledCellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ScrolledCellIdentifier];
//cell.textLabel.text = @"hi";
[cell addSubview:self.scrollView];
}
尝试设置单元格的 textLabel 工作,问题是添加滚动视图。
如果我将这一行添加到代码中:
self.scrollView.frame = CGRectMake(0,-45, 320, 90);
效果很好,但对我来说听起来有些奇怪。发生了什么?
【问题讨论】:
-
澄清一下——为什么需要调整scrollView的frame?
-
因为如果我不调整框架高度为 44 像素,谢谢!
标签: ios uitableview