테이블 뷰에서 셀 악세사리 이미지를 바꾸고 싶을때


먼저 테이블 뷰에서

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    CGRect frame = CGRectMake(0.0, 0.0, 22,22);

  button.frame = frame;

  [button setBackgroundImage:[UIImage imageNamed:@"icon_image"] forState:UIControlStateNormal];

    

    [button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];

    button.backgroundColor = [UIColor clearColor];

    cell.accessoryView = button;

}


위와 같이 하면 이미지가 원하는 데로 변경 됩니다.


그리고 클릭 했을때 기존 악세사리 클릭과 동일하게 동작 하도록..


- (void)checkButtonTapped:(id)sender event:(id)event

{

    NSSet *touches = [event allTouches];

    UITouch *touch = [touches anyObject];

    CGPoint currentTouchPosition = [touch locationInView:self.tableView];

    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];

    if (indexPath != nil)

    {

        [self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath];

    }

}

이렇게 하면 기존에 구현한데로

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

쪽으로 이벤트가 넘어 갑니다.

2012/07/31 10:08 2012/07/31 10:08
젤라피 이 작성.

Trackback URL : 이 글에는 트랙백을 보낼 수 없습니다


당신의 의견을 작성해 주세요.

: 1 : ... 21 : 22 : 23 : 24 : 25 : 26 : 27 : 28 : 29 : ... 105 :