【发布时间】:2015-08-15 18:45:26
【问题描述】:
我想在我的表格视图中有 2 个不同的单元格。
例如:
- 我的第一个单元格有 1 个图像视图和 1 个标签。
- 我的第二个单元格有 4 个图像视图和 4 个标签
有可能吗?我怎样才能做到这一点?
谢谢。
【问题讨论】:
-
您是否使用带有原型单元的情节提要?
-
我有原型单元,我只是想使用静态单元。我只有 2 个单元格,所以没有动态表格视图。
我想在我的表格视图中有 2 个不同的单元格。
例如:
有可能吗?我怎样才能做到这一点?
谢谢。
【问题讨论】:
创建两个自定义 UITableViewCell 并将它们注册到 tableView 与 cellIdentifiers 像 "CellType1" 和 cellType2 然后你可以在 cellForRowAtIndexPath 中做这样的事情
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = nil;
if(indexPath.row == 0)
{
// first row, return cell you want
cellIdentifier = @"CellType1";
}
else
{
// other rows you can return cell you want
cellIdentifier = @"CellType2";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
return cell;
}
【讨论】:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 中创建的单元格
【讨论】: