2017-02-19 3 views
0

ViewController에 사용자 정의 UITableView이 있습니다. 내 사용자 정의 표에는 사용자 정의 UITableViewCells이 있습니다.UITableView didSelectRowAt가 등록되지 않았습니다.

ViewDidLoad :

 self.firstListTable.dataSource = self 
     self.firstListTable.delegate = self 
     self.firstListTable.register(UINib(nibName: "firstQueueCell", bundle: Bundle.main), forCellReuseIdentifier: "firstCell") 

     self.searchListTable.dataSource = self 
     self.searchListTable.delegate = self 
     self.searchListTable.allowsSelection = true 
     self.searchListTable.register(UINib(nibName: "SearchCell", bundle: Bundle.main), forCellReuseIdentifier: "SearchCell") 
     self.searchListTable.separatorStyle = .none 

UITableViewFunctions : 이것은 내 ViewController 내부의 코드

func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) { 
    if tableView == self.searchListTable { 
     print("hello") 
    } 
} 

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){ 
    print("hello") 
} 

didHighlightRowAt 작동하지만 didSelectRowAt하지 않습니다. didSelectRowAtIndexPath: not being called

어떤 다른 원인이있을 수 있습니다 :

나는이 시도?

감사합니다. 당신이 didHighlightRowAtdidSelectRowAt 모두 응답을 원하는 경우

+0

코드에 오류가없는 것 같습니다. 다른 장소가 잘못되어 있다면 다른 코드를 게시 할 수 있습니까? – aircraft

+0

@ user82395214, 코드를 확인하십시오. 그게 잘못이 아니야. 둘 다 응답하고 있습니다. 'didSelectRowAt' 메쏘드의'print' 문을'print ("hello")'에서 다른 무언가로 변경하고 다시 검사 할 수 있습니까? – KrishnaCA

답변

0

,이 같이 당신의 방법 didHighlightRowAt를 덮어 쓸 수 있습니다 :

func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) { 
if tableView == self.searchListTable { 
    print("hello") 

    // this is my OC code ,change it to your swift code 
    [tableView selectRowAtIndexPath:IndexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 

    } 
} 
당신은 didHighlightRowAt 방법 didSelectRowAt 방법으로이 이해할 수

이 충돌, 당신은 두 방법 응답을하려는 경우 특별한 치료를해야합니다.

+0

아, 죄송합니다. 아니요. 내 'didHighlight'는 작동하지만 'didSelect'는 작동하지 않는다고 말하려고합니다. 나는 사용자가 셀과 상호 작용할 필요가 없다. – user82395214

+0

내가 원하는 것을 알고 있지만 코드와 같은 두 가지 방법을 모두 덮어 쓰면 'didSelectRowAt' 응답이 매우 어렵습니다. 사용자는'didSelectRowAt'를 호출하는데 많은 시간을 들여야 만합니다. –

+0

'didHighlightRowAt'에서 원하는 진정한 노력을 말해 줄 수 있습니까? 'didSelectRowAt' 메소드에 당신의 노력을위한 코드를 넣는 것을 제안한다. –

-1
- (nullable NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    if (indexPath.row == 2) { 
     //if you want didSelectRowAtIndexPath not call return nil; 
     return nil; 
    } 
    return indexPath; 
} 
관련 문제