2012-06-30 7 views

답변

1

당신이합니다 (있는 tableView 색상 당신이 원하는 것을 할 수 있도록 기본적으로 분명하다) 기본 색상을 가지고 스토리 보드/XIB에 tableViewCell의 배경을 설정 한 경우에, 당신은 같은 뭔가를 할 수 수행원.

// assume that the background color for the tableView in the storyboard is lightOrange, 
// as seen in http://i47.tinypic.com/nwd45e.png 

- (UITableViewCell*)tableView:(UITableView*)tableView 
     cellForRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    ... the normal code for getting your cell, probably involving DequeueReusableCell ... 

    // yes, the following gets called for every row even when selection doesn't change, 
    // but it is a very small hit. could be replaced by overriding reloadData for the 
    // tableView, but that isn't always desirable. 
    if (tableView.indexPathForSelectedRow) 
     tableView.backgroundColor = [UIColor grayColor]; 
    else 
     tableView.backgroundColor = [UIColor lightOrangeColor]; 

    return cell; 
} 

- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    ... whatever else you would do for a selected row, perhaps a segue or something ... 
    ... (and if part of this is to de-select a row that is already selected, take that ... 
    ... into account as a conditional for the following line of code. 

    tableView.backgroundColor = [UIColor grayColor]; 
} 
+0

그림에서 효과를 내기 위해 배경색과 텍스트의 색을 변경해야 할 수도 있습니다. – KDaker

+0

@KDaker : 동의 함. 나는 이것에 대한 대답을 간단히 편집하는 것을 고려한 다음, 텍스트를 변경하는 방법이 셀의 유형 (제목, 제목 + 설명, 사용자 정의)에 따라 달라질 것임을 깨달았다. –

관련 문제