2012-11-22 5 views
0

공개 표시기가있는 특정 셀을 사용하여 UIImagePicker (다른 셀은 UITextFields 등)을 표시하려고합니다. 지금까지는 UIButton으로 만 수행 할 수있었습니다. 내 작업을 셀에 연결하려고하지만 내 유일한 옵션은 새로운 섹그를 만드는 것입니다. 어떻게하면 좋을까요?UITableViewCell을 액션에 연결

+0

왜 didSelectRowAtIndexPath를 사용하지 않으시겠습니까? – MCKapur

+0

@LuisOscar, 어떻게 증가하는지 알려주세요. 나에게도 너무 적다. –

+0

답을 정확하게 표시하는 것이 적절하다는 것을 알지 못했습니다. 감사합니다. (대부분의 내 질문에 올바른 답을 표시했습니다.) – Andrew

답변

1

사용자가 원하는 셀의 색인 경로 (목록의 첫 번째 셀 등)를 알고있는 경우. 그럼 당신은 사용할 수 있습니다 또한 이벤트 탭에 응답하지 않는 당신의 cellForRowAtIndexPath 다른 모든 세포를 설정할 예정

-(void) tableview:(UITableView *)tableview didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.section == 0 && indexPath.row == 0) { 
     // do some action 
     [tableview deslectRowAtIndexPath:indexPath]; 
     [self someAction]; 
    } 
} 

. 하는 .m 파일에 IB

@property (weak, nonatomic) IBOutlet UITableViewCell *upgradeAppCell; 
@property (weak, nonatomic) IBOutlet UITableViewCell *spreadTheWordCell; 
@property (weak, nonatomic) IBOutlet UITableViewCell *rateOnAppStoreCell; 

를 사용하여 IBOutlets를 작성, .H 파일에

: 당신이 섹션 및 행의 인덱스를 하드 코드하지 않으려면

+0

다른 셀을 터치 이벤트에 응답하지 않게하려면 어떻게해야합니까? 또한, 내 셀은 두 번째 섹션에서 첫 번째 셀이므로 섹션 == 1과 행 == 0이 될 것입니까? – Andrew

+0

보기에서 터치 이벤트를 사용하지 않도록 설정하는 방법이 있다는 것을 알고 있지만, 셀을 위해이 작업을 수행하는 방법을 알지 못합니다. – atreat

0
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath 
{ 
    static NSString *identifier = @"identifier"; 
    YourCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 
    if(!cell) 
    { 
     cell = /*Create your cell*/ 
     [cell.button addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside]; 
    } 

    cell.button.tag = [indexPath row]; 

    return cell; 
} 

-(void)didClickButton:(UIButton *)button 
{ 
    int row = button.tag 
    /*Here you'll be able to know the button of which row has been clicked.*/ 
} 
+0

인터페이스 빌더에서 전체보기를 거의 수행 했으므로 cellForRowAtIndexPath 메소드를 추가하여 복잡하게 만들고 싶지 않았습니다. – Andrew

1

, 당신은 이런 식으로 뭔가를 할 수 :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; 

    if (cell == upgradeAppCell) 
    { 
     [self upgradeApp]; 
    } 
    else if (cell == spreadTheWordCell) 
    { 
     [self spreadTheWord]; 
    } 
    else if (cell == rateOnAppStoreCell) 
    { 
     [self rateOnAppStore]; 
    } 
} 
관련 문제