Я хочу создать один 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;
}
customerCell и FirstCell — два UITableViewCell
для пользовательских ячеек. когда я запускаю этот код, только один раздел не работает и не показывает ячейку, но другой раздел работает, пожалуйста, направьте меня и скажите, в чем моя ошибка.
UITableViewCell
. - person iphonic   schedule 07.04.2014UITableViewCell == FirstCell
? - person iphonic   schedule 07.04.2014NSArray *topLevelObject = [[NSBundle mainBundle] loadNibNamed:@"CustomerCell" owner:nil options:nil];
разве это не должно быть owner:self вместо nil ? - person TheTiger   schedule 07.04.2014