2013-07-04 2 views
-1

나는 내가 새로운 셀이 여기 jQuery과

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath 
     { 

      cell = [self.tableView cellForRowAtIndexPath:indexPath]; 

      cell.imageView.image=[UIImage imageNamed:@"Activity.png"]; 

     } 


    - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 


     [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 

     cell = [self.tableView cellForRowAtIndexPath:indexPath]; 


     cell.imageView.image=[UIImage imageNamed:@"Activity2.png"]; 
     NSUInteger row = indexPath.row; 

    } 

을 선택한 경우 선택에 셀과 셀을 seleced 할 수있는 이미지를 변경하려면 이미지를 추가 할 수있는 테이블 뷰가 아이 패드 응용 프로그램에서 작동하지 deselectrow하면 코드 내가 원하는 의견을 내 의견으로는

 if (indexPath.row==0) { 

     cell.imageView.image=[UIImage imageNamed:@"Activity2.png"]; 
     NSLog(@"Cell Clicked row 0"); 


     if(indexPath.row==1){ 


     NSLog(@"Cell Clicked row 1 in 0"); 

     cell.imageView.image=[UIImage imageNamed:@"Catalog"]; 

     } 

     } 
    if (indexPath.row==1) { 

    cell.imageView.image=[UIImage imageNamed:@"Catalog2.png"]; 
    NSLog(@"Cell Clicked row 1"); 


    if(indexPath.row==0){ 


     NSLog(@"Cell Clicked row 0 in 1"); 


     cell.imageView.image=[UIImage imageNamed:@"Activity"]; 

    } 


} 

새 코드를 추가하면 새 셀을 선택했을 때 셀에 이미지가 어떻게 표시되는지 새 코드가 추가되었습니다.

+1

문제가 무엇입니까? 선택 취소하면 작동하지 않는다는 의미입니까? –

+0

예 선택된 행 0 Activity2.png에 이미지를 지정하고 행 1을 선택하면 해당 행 0에 Activit, 행이 있어야하며 행 1에는 Row2.png가 있어야합니다. –

답변

1

다른 모든 TableViewCell을 루프하여 이미지를 설정해야합니다.

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    [aTableView deselectRowAtIndexPath:indexPath animated:YES]; 

    NSUInteger row = indexPath.row; 
    for (int i=0; i<=4; i++) { 
     UITableViewCell *cell = [aTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:indexPath.section]]; 

     cell.imageView.image=nil; 
    } 
    UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath]; 
    cell.imageView.image=[UIImage imageNamed:@"Default.png"]; 

} 
+0

행 1이 선택되면 Activity2.png가 표시됩니다. 행 2가 선택되면 Catalog2가 표시되고 행 1은 Activity not activity2를 표시합니다. –

6
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES]; 

사용이 내가 자기에게 위임, 데이터 소스를 설정하고 모두 아이폰에 대한 다음과 같은 코드를 사용했다

0

가 작동 한 아이 패드

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    cell.imageView.image = [UIImage imageNamed:@"imgres.jpeg"]; 

} 
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    cell.imageView.image = [UIImage imageNamed:@"images.jpg"]; 

}