2013-06-06 3 views
1

그래서 기술적으로는 UISwitch 아니라 단지 UISwitch (https://github.com/domesticcatsoftware/DCRoundSwitch)indexPath는 tableView 셀의 Custom UISwitch에 대해 null을 반환합니까?

나는 테이블의 모든 행에이 DCRoundSwitch을 사용하고처럼 동작 사용자 정의 클래스와의 UIView 아니다. DCRoundSwitch가있는 행의 indexPath를 가져오고 싶지만 null을 반환합니다. 여기

가 DCRoundSwitch 구성하는 방법입니다 (값이 변경 사용) : 당신이 볼 수 있듯이

-(void)togglePublic:(UIControl *)button withEvent:(UIEvent *)event { 


    DCRoundSwitch *switch1 = (DCRoundSwitch *)button; 
    UITableViewCell *cell = (UITableViewCell *)switch1.superview; 
    NSIndexPath *indexPath = [self.tableview indexPathForCell:cell]; 

    NSLog(@"PUBLICSWITCH PRESSED %@", indexPath); 


    //NSIndexPath * indexPath = [self.tableview indexPathForRowAtPoint:[[[event touchesForView: button] anyObject] locationInView: self.tableview]]; 


    if (indexPath == nil){ 

     return; 

    } 


    AHBContact *contact = [self.contacts[indexPath.section] allValues][0][indexPath.row]; 

    NSLog(@"Public switch toggled for: %@", contact); 


} 

가의 indexPath가 마치 nil을 반환

Tied Events

여기 내 togglePublic 방법입니다 "Public switch toggled :"로그 메시지에 도달하기 전에 항상 메소드가 리턴됩니다.

답변

4

여기서 switch1.superview가 실제로 셀을 반환하는지 확인하십시오.

때로는 예상치 못한 부모보기의 이상한 레이어가 표시됩니다.

+0

좋은 아이디어. 돌아 오는 것을 확인하는 좋은/빠른 방법은 무엇입니까? – Rohan

+0

nvm. 그것을 얻었다 - 당신이 옳았다! 기대했던 것보다 한 아이가 낮았다. – Rohan

관련 문제