2012-08-08 3 views
0

은 내가 아래 그림과 같은 테이블보기를 "사용자 행을 선택할 때이 그림을 변경해야"하지만 난마르크 및 jQuery과 셀 해제 상자

당신이 사전에 나에게

감사 도와주세요 것입니다 방법을 모르는 :이 방법 didSelectRowAtIndexPath를 사용해야!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
NSString *key = [[self sectionKeys] objectAtIndex:[indexPath section]]; 
NSArray *contents = [[self sectionContents] objectForKey:key]; 
NSString *contentForThisRow = [contents objectAtIndex:[indexPath row]]; 

if (indexPath.section != 2) { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 
    cell.textLabel.text =contentForThisRow; 
    return cell; 
} 
else { 
    CheckBoxCompensationViewCell *cell = (CheckBoxCompensationViewCell*)[tableView 
dequeueReusableCellWithIdentifier:@"CheckBoxCompensationViewCell"]; 

    cell.imageView.image=[UIImage imageNamed:@"emptycheck-box.png"]; 
    cell.checkBox.image = image; 
    if(indexPath.row == 0){ 
     cell.compensationText.text [email protected]"Red"; 
    } 
    else if (indexPath.row == 1){ 
     cell.compensationText.text [email protected]"Green"; 

    }else if(indexPath.row == 2){ 
     cell.compensationText.text [email protected]"Blue"; 
    } 
    return cell; 
} 
} 



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
// I don't know what should I have here , probably mark box image but I don't know how 
} 

답변

2
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSIndexPath *previousPath = self.selectedIndexPath; 
    self.selectedIndexPath = indexPath; 
    [tableView reloadRowsAtIndexPaths:@[previousPath, indexPath] withRowAnimation:UITableViewRowAnimationNone]; 
} 

음이 아주 기본이고, 늘 셀을 선택 해제, 당신은 cellForRowAtIndexPath에서 선택된 인덱스 경로의 상태를 확인해야합니다 :

+0

(12) 감사하지만 나는 한 당신이 indexPath이 현재 선택되어있는 나타내는 속성을 가질 필요가 –

+0

선택의 제한이 수있는 방법을 알고, 난 당신이 – wattson12

+0

12 내 업데이트 된 대답을 참조 I 그걸 보았다. –

0
여기

내 코드입니다

정말 쉽습니다. 사용자가 셀을 선택하면 데이터 모델을 업데이트하고 테이블을 다시로드해야합니다. 데이터 모델은 버튼 상태를 저장합니다. cellForRowAtIndexPath 메소드에서 데이터 모델 상태에 따라 설정 버튼을 수행하십시오. 그게 다야.