2014-07-20 6 views
0

나는 존재하는 UserView 및 existUserCustomCell 클래스가 있어야합니다.UIButton을 통해 매개 변수를 전달하는 방법

existUserView의 코드 : existUserCustomCell에

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    ExistUserCustomCell *cell = (ExistUserCustomCell*)[tableView dequeueReusableCellWithIdentifier:@"ExistUserCustomCell"]; 

    KidManager *kid = [self.kidsArray objectAtIndex:indexPath.row]; 
    cell.kidName.text = kid.firstName; 
    if([kid.inside isEqualToString:@"1"]){ 
     cell.kidStatus. text = @"some string"; 
    }else{ 
     cell.kidStatus.text = @"some string"; 
    } 

    return cell; 
} 

번호 : I '는 existUserCustomCell'모두 버튼 기능 'existUserView'의 데이터를 전달할 때 열을 알아야

- (IBAction)reportMissing:(id)sender { 

} 

- (IBAction)callTeacher:(id)sender { 

} 

나는 그들을 눌러. 어떻게하면 가장 좋은 방법일까요?

+0

왜 셀에 행을 알 필요가 있습니까? 그것은 거의 필요하지 않습니다. – rmaddy

+0

다른 클래스에서 처리하는 사용자 정의 셀 .. – OshriALM

+0

그건 내 질문에 대답하지 않습니다. – rmaddy

답변

2

보기 컨트롤러에서 셀로 데이터를 전달해야하는 경우 셀 클래스에 속성 (또는 2 또는 3)을 추가하십시오. cellForRowAtIndexPath에 셀을 설정할 때 속성을 설정하십시오. 그런 다음 셀 처리 방법 (단추 처리기 포함)에서 필요에 따라 데이터에 액세스 할 수 있습니다.

하면 세포 클래스에 속성을 추가

@interface ExistUserCustomCell : UITableViewCell 

// add this to anything you have 
@property (nonatomic, strong) KindManager *kid; 

@end 

이제 버튼 방법은 액세스 할 수 있습니다

테이블 뷰 컨트롤러에서 다음
- (IBAction)reportMissing:(id)sender { 
    // access self.kid to get data 
    // anything else you need 
} 

: 난

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    ExistUserCustomCell *cell = (ExistUserCustomCell*)[tableView dequeueReusableCellWithIdentifier:@"ExistUserCustomCell"]; 

    KidManager *kid = [self.kidsArray objectAtIndex:indexPath.row]; 
    cell.kid = kid; 
    cell.kidName.text = kid.firstName; 
    if([kid.inside isEqualToString:@"1"]){ 
     cell.kidStatus. text = @"some string"; 
    }else{ 
     cell.kidStatus.text = @"some string"; 
    } 

    return cell; 
} 

셀에 필요한 데이터가 KidManager이라고 추측합니다. 필요에 따라 조정하십시오.

나는 짐작할 만하다면 셀이 cellForRowAtIndexPath 메서드의 로직 대신 데이터로 설정되어야한다.

+0

죄송합니다. ios가 새로 생겼습니다. 내가 말했듯이, 나는 2 개의 수업을 가지고있다. 하나는 테이블 뷰를 처리하고 다른 하나는 tableview 셀 (사용자 정의 셀)을 처리합니다. 셀에 2 개의 단추가있어 사용자 지정 셀 클래스의 IBAction입니다. IBAction 함수에 데이터를 전달하여 각 셀 indexPath에 전달해야합니다. 내가 어떻게 할 수 있니? – OshriALM

+1

나는 이미 너에게 말했다. 셀 클래스의 데이터에 대한 속성을 추가하면 셀의 단추 메서드가 데이터에 액세스 할 수 있습니다. 자세한 내용은 업데이트 된 답변을 참조하십시오. – rmaddy

관련 문제