iPhone App2011.09.23 10:42
여러가지 방법을 해보았다.

물론 Custom Cell Class에서 Action을 걸어서 하는 방법이 있지만 나는 TableView가 있는 클래스의 Data Array를 사용해야만 했기때문에

TableView가 있는 Class에서 Action을 받고 싶었다. (이것도 여러가지 방법으로 해봄)

일단 

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

{   

    BoardCustomCell *cell = (BoardCustomCell *)[tableView dequeueReusableCellWithIdentifier:BoardCustomCellIdentifier];

    

    // NSUInteger row = indexPath.row;

    

if(cell == nil)

{

        cell = [BoardCustomCell cellWithNib];

}        

    

    NSMutableDictionary* commentData = (NSMutableDictionary*)[commentDataArray objectAtIndex:indexPath.row];    

    cell.contentLabel.text = [commentData objectForKey:@"CmtContent"];

    cell.memberNameLabel.text = [commentData objectForKey:@"MemberName"];    

    cell.dateLabel.text = [commentData objectForKey:@"CreateDate"];

    cell.memberLevelLabel.text = [commentData objectForKey:@"PntSumLv"];

    cell.memberPointLabel.text = [commentData objectForKey:@"ReCmdCount"];


    

    UIImage *image = [UIImage   imageNamed:@"delbtn.png"];    

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);

    button.frame = frame;

    [button setBackgroundImage:image forState:UIControlStateNormal];    

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

    cell.accessoryView = button;


아래처럼 cell.accesooryView에 버튼 생성해서 넣었다.  

액션 셀렉터에서

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

{

    NSSet *touches = [event allTouches];

    UITouch *touch = [touches anyObject];

    CGPoint currentTouchPosition = [touch locationInView:commentTableView];

    NSIndexPath *indexPath = [commentTableView indexPathForRowAtPoint: currentTouchPosition];

    NSMutableDictionary* commentData = (NSMutableDictionary*)[commentDataArray objectAtIndex:indexPath.row];   

    

    NSString* cmtIdx= [commentData objectForKey:@"CmtIdx"];


    [self performSelector:@selector(sendSympathy:) withObject:cmtIdx afterDelay:0.5];

}


이렇게 구현을 했다.
 

참고 :http://www.edumobile.org/iphone/iphone-programming-tutorials/impliment-a-custom-accessory-view-for-your-uitableview-in-iphone/
 
Posted by 동동(이재동)