C.J*_*hns 1 cocoa-touch objective-c uitableview ios
我希望根据您在Interface Builder中设置自定义单元格的值动态设置单元格高度.这没有用,所以我继续前进并在Apples文档中找到了可用于设置单元格高度的方法 - tableView:heightForRowAtIndexPath:
但是我不确定我是否正确使用它,因为我的tableviewcells没有调整它们的高度它们都保持相同的标准尺寸.这是我在这里使用的代码.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Set cell height
[self tableView:tableView heightForRowAtIndexPath:indexPath];
// Configure the cell using custom cell
[[NSBundle mainBundle] loadNibNamed:@"CustomcellA" owner:self options:nil];
cell = customcellA; // customcellA getters and setters are set up in .h
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 44;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激
让我们说第三个单元格的高度是两倍:
- (CGFloat) tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 2)
return 88;
return 44;
}
Run Code Online (Sandbox Code Playgroud)
tableView将调用此方法.
你不应该这样做:
[self tableView:tableView heightForRowAtIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)
您如何确保正确的单元格的indexPath被识别为其他尺寸,由您决定.
一般规则:
如果您实施委托协议的方法,您将永远不会自己调用它.只有具有符合协议的委托的类的对象才会调用委托方法.
| 归档时间: |
|
| 查看次数: |
4528 次 |
| 最近记录: |