gpt4 book ai didi

ios - UITableView 中的两个不同的 UITableViewCell

转载 作者:行者123 更新时间:2023-11-29 03:04:43 24 4
gpt4 key购买 nike

我想创建一个具有 2 个部分行的 TableView。此表有 2 个部分(第一部分有 1 个单元格,第二部分有 3 个单元格)

注意:第一部分的单元格与第二部分的单元格不同。

这是我的代码,但不起作用!!!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

NSArray *name = [_names objectForKey:key];
static NSString *CellIdentifier2 = @"CustomerCell";

if (indexPath.section == 0) {

static NSString *CellIdentifier = @"myCell";
FirstCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[FirstCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.nameLable.text = [NSString stringWithFormat:@"blue"];
cell.numberLable.text = [NSString stringWithFormat:@"1212432543"];
cell.profileImage.image = [UIImage imageNamed: @"profile.png"];

return cell;
//this part not working !!! XD

}
else if (indexPath.section >= 1) {

CustomerCell *cell = (CustomerCell *)[self.table dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell == nil)
{
NSArray *topLevelObject = [[NSBundle mainBundle] loadNibNamed:@"CustomerCell" owner:nil options:nil];

for (id currentObject in topLevelObject) {
if ([currentObject isKindOfClass:[CustomerCell class]]) {
cell = (CustomerCell *)currentObject;
break;
}
}
}
// Configure the cell...
cell.titleLable.text = [name objectAtIndex:indexPath.row];
return cell;
}
return nil;
}

customerCellFirstCell 是自定义单元格的两个 UITableViewCell。当我只运行此代码时,第一部分不工作并且不显示单元格但另一部分工作请指导我并告诉我我的错误在哪里。

最佳答案

试试这个:

FirstCell *cell = (FirstCell *)[tableView dequeueReusableCellWithIdentifier:strEvalIdentifier]; 
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FirstCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}

关于ios - UITableView 中的两个不同的 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22911351/

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