gpt4 book ai didi

xcode - 如何使用 Storyboard 在一个 TableView 中添加不同的自定义单元格?

转载 作者:行者123 更新时间:2023-12-04 00:07:46 26 4
gpt4 key购买 nike

我想通过使用 Storyboard 在一个 Tableview 中添加 2 个或更多不同的自定义单元格。
我知道如何在没有 Storyboard 的情况下添加不同的单元格。我总是这样做:

static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//pictureCell = [[DetailPictureCell alloc]init];//(DetailPictureCell *)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];
pictureCell.header = true;
[pictureCell setHeader];
if (cell == nil) {
if ([indexPath row] == 0) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"HeaderAngebotViewCell" owner:self options:nil];
NSLog(@"New Header Cell");
}
if([indexPath row] ==1){
NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"productCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}

现在我的问题是:我怎么能用 Storyboard做到这一点?
可以添加一个自定义单元格。但我不能添加两个不同的单元格。你能帮我吗?

最佳答案

在表格 View 的属性检查器中,选择“动态原型(prototype)”并在其下方选择原型(prototype)单元格的数量。给每个单元格一个不同的标识符,并在 cellForRowAtIndexPath 中的单元格出列时,使用基于 indexPath 的适当标识符。

enter image description here

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier;
if (indexPath.row == 0) {
identifier = @"OneCellId";
} else if (indexPath.row == 1) {
identifier = @"OtherCellId";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

//configure cell...
}

关于xcode - 如何使用 Storyboard 在一个 TableView 中添加不同的自定义单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17863417/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com