我需要有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的scrollView,但是它添加在中间的细胞而不是顶部 .
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工作,问题是添加scrollView .
如果我将此行添加到代码中:
self.scrollView.frame = CGRectMake(0,-45, 320, 90);
它工作得很完美,但对我来说听起来有些奇怪 . 怎么了?
3 回答
在添加之前,将scrollView的框架设置为单元格的边界 .
所以
调试... NSLog ....输出事物的帧,这样你就可以看到它们的位置,而不是你想要它们的位置 . 用它来输出框架坐标:
或定义一个很好的快捷方式,因为我一直使用它
那你就可以做
它只是将scrollview放入tableviewcell,无论它的高度是44还是90 .
我用这段代码解决了我的问题:
我不知道这是不是错了但是有效......