2012-10-01 2 views
0

단추를 클릭하면 이미지가 이미지 단추 위에 추가되어 이미지가 변경됩니다. didSelectRow 메서드에 논리를 써야합니다. 그러므로 내가 그 이미지를 얻을 수있는 다음 줄을 쓸 필요는 추가 :didSelectRow 메서드에서 cell (CellForRow 메서드에서 반환 한) 사용

button=[UIButton alloc] initWithFrame:CGRectMake(230,0,40,40]; 
button.addTarget: self action: @selector(buttonPressed:withEvent:) forControlEvents:UIControlEventTouchUpInside]; 
button.tag=indexPath.row; 
[button setImage: [UIImage imageNamed:@"a.png"] forState:UIControlStateNormal]; 
[cell addSubview: button]; 

를이 내가 cellForRow에서 위의 코드를 작성할 때 셀이 방법에서 정의하지 않는 한,이 didSelectRow에서 작동하지 않습니다 작동하지만.

답변

0

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

    UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath]; 
    for (UIButton *button in cell.subviews) { 
     if (button.tag==indexPath.row) { 
      [button setImage: [UIImage imageNamed:@"another.png"] forState:UIControlStateNormal]; 
     } 
    } 
} 
시도를 얻을 수 didSelectRow이 시도
0

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];