【问题标题】:reload data fail within tableviewController在 tableviewController 中重新加载数据失败
【发布时间】:2016-11-15 09:03:05
【问题描述】:
class SelectionBoxViewController: UITableViewController,UISearchBarDelegate {
    var searchbar = UISearchBar()

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

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

它在tableView.reloadData()EXC_BAD_ACCESS 崩溃。

【问题讨论】:

  • 发布崩溃的堆栈跟踪,以便我们了解导致崩溃的原因
  • 在哪里可以找到 crashh 的堆栈跟踪

标签: ios swift uitableview uisearchbar


【解决方案1】:

可能是两件事(包括):

  • 您没有将类链接到情节提要中的 tableView
  • UITableViewDataSource 所需的委托未实现

尝试将此函数添加到您的类中:

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

还有这个:

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

【讨论】:

  • 注意它是一个UITableViewController,那些子弹应该是默认存在的。
  • 艾哈迈德是对的。我只是没有把所有的代码都放在这里
猜你喜欢
  • 2020-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-05
  • 2019-07-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多