TableView
のViewController
の内部でdidSelectRowAt
メソッドが機能するのに問題があります。私はすでにテーブルのdelegate
とdata source
がViewController
コードに設定されていることを確認しました。このViewController
はtableview
セルに検索クエリの結果をAPIに入力し、セルデータのレンダリングが正常に動作しています。didSelectRowAtをTableViewで使用することができません
登録していないのはちょうどdidSelectRowAt
メソッドです。私は手動でMain.storyboardに同じデリゲート情報を追加しようとしましたが、少し+
という記号はポップアップウィンドウをトリガーしません。 Main.storyboard
に修正が必要なものがあるかどうか疑問に思っています。 ViewController
とTableView
接続インスペクタの画像も添付しました。私はiOS開発の初心者であり、モバイル・デザインのためのグラフィック・インターフェースに関する多くの経験はないので、私はそれが何かだと仮定していますが、おそらく私は間違っています。
ここに私のコードの基本的なバージョンです:
class SearchViewController: UIViewController, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
@IBOutlet var searchBar: UISearchBar!
...variable declarations ....
override func viewDidLoad() {
super.viewDidLoad()
self.hideKeyboardWhenTappedAround()
searchResults = []
searchBar.delegate = self
tableView.dataSource = self
tableView.delegate = self
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1;
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return searchResults!.count;
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "searchTableViewCell", for: indexPath) as! SearchTableViewCell
if(searchActive && !(self.searchResults?.isEmpty)!) {
(doing some stuff with search results here...works fine)
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("hello!")
}
func searchBar(_ searchBar: UISearchBar,
textDidChange searchText: String) {
print("search text \(searchText)")
getSearchResultJSON(term: searchText) { json in
let data = json as! [Dictionary<String, String>]
self.searchResults = data
}
self.tableView.reloadData()
}
...
}
[]
[]
EDIT:検索非同期機能は何も変更された場合のための健全性チェックとしては、 、私はちょうどすべての検索関連のコードを削除し、ハードコードされたダミー変数配列からtableviewを埋めることを試みた。それはダミー変数を表示するように機能しましたが、セルを選択して反応を得る能力はまだありません。私はdidSelectRow atの代わりにdidDeSelectRowAtを使ってタイプミスをしていたということをいくつか見てきましたが、これは修正されましたが、動作は同じです。
これは、私はあなたがこれを使用して、まあdidDeselectRowAt
代わりのdidSelectRowAt
編集に
を使用している
viewdidloadメソッドでデリゲート宣言を削除し、ストーリーボードでtableviewデリゲートを設定しようとしました –
テーブルセルの上でタブジェスチャまたはボタンを使用しましたか? –
didDeselectRowAtメソッドを使用しています。 – Niharika