簡體   English   中英

在tableviewController中重新加載數據失敗

[英]reload data fail within tableviewController

class SelectionBoxViewController: UITableViewController,UISearchBarDelegate {
    var searchbar = UISearchBar()

    override func viewDidLoad() {
        super.viewDidLoad()
        searchbar.delegate = self
    }

    func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {   
        tableView.reloadData()
    }
}

它使用EXC_BAD_ACCESStableView.reloadData() EXC_BAD_ACCESS

可能是兩件事(包括):

  • 您沒有將類鏈接到情節提要中的tableView
  • 未實現UITableViewDataSource的必需委托

嘗試將此函數添加到您的類中:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 0
}

還有這個:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    return UITableViewCell()
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM