我無法讓didSelectRowAt
方法在常規ViewController
內工作TableView
。我已經確定該表的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()
}
...
}
[]
[]
編輯:的健全性檢查,如果搜索異步函數改變什麼,我只是嘗試刪除所有與搜索相關的代碼,並從硬編碼的虛擬變量數組中填充tableview。它的工作是顯示虛擬變量,但仍然沒有能力選擇一個單元格並得到任何反應。我還看到一對夫婦提到,我以前有一個與didDeSelectRowAt而不是didSelectRow在一個錯字,已修復,但行爲是相同的。
這最終被涉及到發生在我寫
嘗試刪除委託聲明在viewDidLoad方法和你接管表格單元格的任何tapgesture或按鈕來設置的tableview委託在故事板 –
? –
您正在使用didDeselectRowAt方法。 – Niharika