iPhone App2011. 9. 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 동동(이재동)
iPhone App2011. 7. 27. 17:18

일단 UITableViewCell Class를 하나 만들고 Empty Xib 파일도 만든다.

201107271711.jpg

일단 뷰에 UITableViewCell을 추가하고

그뒤 저렇게 Files'Owner에서 class를 UIViewController로 바꾼다.

이번에는 UITableViewCell에 가서


201107271715.jpg

이렇게 바꾸고


201107271716.jpg

identifer도 바꾼다. 바꾸면 이렇게 된다.


201107271716.jpg

자 이제 클래스 파일을 수정하자

헤더파일이다

#import <UIKit/UIKit.h>


#define HugeBoardCellIdentifier @"HugeBoardCellIdentifier"


@interface HugeBoardCell : UITableViewCell {

IBOutlet UILabel *titleLabel;

IBOutlet UILabel *idxLabel;

}


@property (nonatomic,retain) IBOutlet UILabel *titleLabel;

@property (nonatomic,retain) IBOutlet UILabel *idxLabel;

+ (id)cellWithNib;


@end


딴건 중요하지 않고 cellWithNib이 중요하다
실제 구현부에

+ (id)cellWithNib

{

HugeBoardCell *cell;

UIViewController *controller = [[UIViewController alloc] initWithNibName:@"HugeBoardCell" bundle:nil];

cell = (HugeBoardCell *)controller.view;

[controller release];

return cell;

}


이렇게 추가한다.

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

  HugeBoardCell *cell = (HugeBoardCell *)[tableView dequeueReusableCellWithIdentifier:HugeBoardCellIdentifier];

  

if (cell == nil) {   

cell = [HugeBoardCell cellWithNib];   

}

HugeBoardData* hd = [boardData objectAtIndex:indexPath.row];

cell.titleLabel.text = [NSString stringWithFormat:@"%@", hd.title];

cell.idxLabel.text= [NSString stringWithFormat:@"%@ : ", hd.idx];


실제 사용하는부분에 이렇게 사용했다 ,
Posted by 동동(이재동)