使用Xcode 4.6,我試圖顯示一個典型的UITableView,其單元格帶有字幕。UITableViewCell字幕。沒有得到它的工作
如果我沒看錯的,代碼是這樣的:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
Test *myTest = [self listTests][indexPath.row];
cell.textLabel.text = [myTest name];
UIFont *cellFont = [UIFont systemFontOfSize:16.0];
cell.textLabel.font = cellFont;
UIFont *detailFont = [UIFont systemFontOfSize:12.0];
NSMutableString *detailText = [NSMutableString stringWithFormat:@"%d", [myTest numQuestions]];
[detailText appendString:@" preguntas."];
cell.detailTextLabel.text = detailText;
cell.detailTextLabel.font = detailFont;
return cell;
}
出於某種原因,它從來沒有穿過這行代碼:
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
使細胞從不初始化爲UITableViewCellStyleSubtitle
。
它以某種方式得到總是從一開始有效的細胞做[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
我能是做錯了什麼時候?
它真的很受歡迎。我總是使用這個代碼,它通常工作。我還能在其他地方做錯什麼?
你在IB中使用自定義單元格嗎? – 2013-03-08 11:07:40
你是故事板和原型單元嗎? – katzenhut 2013-03-08 11:07:48