У меня есть один UITableView, который я хочу иметь три раздела - каждый из которых состоит из пользовательских ячеек.
Первый раздел должен иметь нормальную высоту и ширину ячейки, но второй раздел (с твитами, подписчиками и т. Д.) Я хочу разместить по два ряда в одном ряду, как во втором разделе на рисунке ниже. Я пытался изменить ширину ячеек, но это не работает.
Я вставил приведенный ниже код для отображения ячеек, но на данный момент он не выдает никаких ошибок, просто не делает то, что я хочу! (У него также есть предупреждение: «управление достигает конца не пустой функции, хотя в} после последней возвращаемой ячейки.
Изображение (второй раздел «Твиты, подписчики и т. Д.» - это то, что я хочу воссоздать):
альтернативный текст http://technopedia.info/wp-content/uploads/2009/09/tweetie22.jpg
И код:
- (UITableViewCell *) tableView: (UITableView *) таблица cellForRowAtIndexPath: (NSIndexPath *) indexPath {
if(indexPath.section==0) {
static NSString *kCellIdentifier = @"SongDetailCell";
UITableViewCell *cell = (UITableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:kCellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
switch (indexPath.row) {
case 0: {
cell.textLabel.text = NSLocalizedString(@"District:", @"district label");
cell.detailTextLabel.text = dog.district;
} break;
case 1: {
cell.textLabel.text = NSLocalizedString(@"Location:", @"location label");
cell.detailTextLabel.text = dog.locations;
} break;
case 2: {
cell.textLabel.text = NSLocalizedString(@"Dog Name:", @"name label");
cell.detailTextLabel.text = dog.names;
} break;
case 3: {
cell.textLabel.text = NSLocalizedString(@"Last Updated:", @"last updated label");
cell.detailTextLabel.text = [incident.lastUpdated substringToIndex:[dog.lastUpdated length] - 1];
} break;
case 4: {
cell.textLabel.text = NSLocalizedString(@"Type:", @"type label");
cell.detailTextLabel.text = dog.types;
} break;
case 5: {
cell.textLabel.text = NSLocalizedString(@"Status:", @"status label");
cell.detailTextLabel.text = dog.status;
} break;
case 6: {
cell.textLabel.text = NSLocalizedString(@"Size:", @"size label");
cell.detailTextLabel.text = dog.sizes;
} break;
case 7: {
cell.textLabel.text = NSLocalizedString(@"Applicances:", @"appliances label");
cell.detailTextLabel.text = dog.appliances;
} break;
case 8: {
cell.textLabel.text = NSLocalizedString(@"Started:", @"started label");
cell.detailTextLabel.text = dog.startDate;
} break;
}
return cell;
}
if(indexPath.section==1) {
static NSString *CellIdentifier = @"ContactCell";
ContactViewCell *cell = (ContactViewCell *)
[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ContactTableCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (ContactViewCell *) currentObject;
break;
}
}
switch (indexPath.row) {
case 0: {
cell.testLabel.text = @"Title";
} break;
case 1: {
cell.testLabel.text = @"Title";
} break;
case 2: {
cell.testLabel.text = @"Title";
} break;
case 3: {
cell.testLabel.text = @"Title";
} break;
case 4: {
cell.testLabel.text = @"Title";
} break;
}
return cell;
}
}