2
當我建立和分析時,我被告知單元格永遠不會得到一個值...這似乎是我的邏輯錯誤,但然後應用程序崩潰試圖加載表。所以......爲什麼來?tableview:cellforrowatindexpath與多種細胞類型
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *Cell1Identifier = @"Cell1";
static NSString *Cell2Identifier = @"Cell2";
static NSString *Cell3Identifier = @"Cell3";
UITableViewCell *cell;
if ([indexPath section] == 0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cell1Identifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:Cell1Identifier] autorelease];
}
}
else if ([indexPath section] == 1) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cell3Identifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:Cell3Identifier] autorelease];
}
}
else {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cell2Identifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:Cell2Identifier] autorelease];
}
}
// Configure the cell...
[self configureCell:cell
atIndexPath:indexPath];
return cell;
}