2011-06-07 44 views
1

爲了更好的用戶體驗,我希望我的UITableViewCell在用戶點擊時具有默認的藍色樣式。目前,根本沒有造型。這不是我需要的嗎?當選擇UITableViewCell時使用默認的藍色背景

- (void)tableView:(UITableView *)tableView 
    didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView selectRowAtIndexPath:indexPath 
     animated:NO scrollPosition:UITableViewScrollPositionNone]; 
    // [The rest of my code here that loads up the detail view] 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView 
    cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // [bunch of code] 
    UITableViewCell *cell = [[[UITableViewCell alloc] 
     initWithStyle:UITableViewCellStyleSubtitle 
     reuseIdentifier:PlaceholderCellIdentifier] autorelease]; 
    // [bunch of code that sets the text of the cell]; 
    return cell; 
} 

回答

2

轉到的cellForRowAtIndexPath和使用

cell.selectionStyle= UITableViewCellSelectionStyleBlue; 
+0

這解決了這個問題。我不知道爲什麼。根據[UITableViewCell文檔](http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html),「UITableViewCellSelectionStyleBlue」已經是默認樣式。另外,我已經看到其他示例代碼沒有重新定義這個默認樣式,但是在單元被點擊時正確顯示樣式。 – JoJo 2011-06-07 19:33:05