2017-02-19 8 views
0

ViewControllerにカスタムUITableViewがあります。私のカスタムテーブルはカスタムUITableViewCellsです。これは私のViewController内のコードです: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

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

他にどのような原因があるかもしれませんか?

ありがとうございます!

+0

あなたのコードにエラーがないように見えますが、他の場所が間違っているかどうか見てみましょう。 – aircraft

+0

@ user82395214、コードを確認してください。何も間違っていません。どちらも応答しています。 'didSelectRowAt'メソッドの' print'文を 'print(" hello ")'から別のものに変更してもう一度チェックできますか? – KrishnaCA

答えて

0

あなたはdidHighlightRowAtdidSelectRowAt両方の応答をしたい場合は、このようなあなたの方法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; 
}