물론 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/
'iPhone App' 카테고리의 다른 글
[iphone] viewDidAppear 한번만 호출하기 (0) | 2011.09.23 |
---|---|
[iphone] viewDidAppear 호출이 안될때... (0) | 2011.09.23 |
[iphone] 아이폰에서 ipaddress 얻어오기 (0) | 2011.09.22 |
[iphone] 발전(업그레이드)된 XML Parser 사용하기 (0) | 2011.09.21 |
[iphone] 데이터(XML)를 Post 방식으로 받아서 처리(WCF Rest) (0) | 2011.09.19 |