2017-12-15 2 views
1

레이블과 버튼이 포함 된 사용자 정의 셀을 만들었습니다. 이 XIB는 다른 tableview 클래스에 등록됩니다. 이제 버튼을 클릭하면 tableview에 다른 행을 삽입하기 위해 버튼의 인덱스 경로를 알아야합니다.객관적인 C 언어의 다른 클래스에서 사용자 정의 셀 속성 색인 경로를 얻는 방법

Sample image

+0

당신이 속성으로 indexPath를 추가하고 cellForRow 방법이처럼 –

+0

에서 설정 할 수 있습니까? in cellFor RowAtIndexPath {cell.buttonIndexPath = indexpath; } –

답변

1

당신이 시도 할 수 있습니다,

- (void)btnAction:(id)sender 
{ 
    NSIndexPath *indexPath; 

    id vwSuperView = sender; 

    while (![vwSuperView isKindOfClass:[UITableViewCell class]]) 
    { 
     vwSuperView = [vwSuperView superview]; 
    } 

    indexPath = [self.tableView indexPathForRowAtPoint:[(UITableViewCell *)vwSuperView center]]; 
} 
0
-(void)getAddAction:(id) sender 
{ 
    UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview]; 
    NSIndexPath *clickedButtonIndexPath = [messagesTableView indexPathForCell:clickedCell]; 

    int selectedIndexPath = clickedButtonIndexPath.row; 
    NSLog(@”SelectedIndexPath: %d”, selectedIndexPath); 

    // get value/object from your array 
    NSString *userInfo = [userInformationArray objectAtIndex:selectedIndexPath]; 
    NSLog(@”userInfo : %@”, userInfo); 
} 
관련 문제