2011-11-01 110 views
2

嗨,我正在實施一個UITableView。我打算使用不同的設置取決於特定的標準電池的不同UITableViewCellStyle(見下面的代碼片段)如何爲同一個表中的不同單元格設置不同的UITableViewCellStyle?

if (cell == nil) 
{ 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:PlaceholderCellIdentifier]autorelease]; 
    cell.textLabel.font = [UIFont boldSystemFontOfSize:14]; 
    cell.textLabel.lineBreakMode = UILineBreakModeCharacterWrap; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    cell.textLabel.numberOfLines = 0; 
} 

if ([genericObj.type isEqualToString:@"question"]) 
{ 
    //I want to user UITableViewCellStyleValue1 
} 
else if([genericObj.type isEqualToString:@"topic"]) 
{ 
    //I want to user UITableViewCellStyleValue2 
} 
else //user 
{ 
    //I want to user UITableViewCellStyleSubtitle 
} 

誰能告訴我我怎麼能相應地改變uitableviewcellstyle?

回答

3

在初始化後,您無法更改UITableViewCell的樣式。

而是使用不同的重用標識符。

將if放在if(cell == nil)行之上。從那些出列您需要的不同類型的細胞。

如果單元格爲零,則在另一個塊中初始化您需要的單元。

相關問題