应用程序无法打印到控制台SearchBar.text

时间:2016-11-29 22:52:53

标签: ios xcode

我正在使用搜索栏制作简单的应用。

我的目标是放置文字,我在搜索栏中输入TableCell。但是,在测试时,即使在控制台中,文本也不会打印。

为什么会这样呢?

extension SearchViewController: UISearchBarDelegate {

func searchBarSearchButtonClicked(searchBar: UISearchBar) {
    print("The search text is: '\(searchBar.text!)")
    searchResults = [String]()

    for i in 0...2 {
        searchResults.append(String(format: "Fake results %d for '%@'",i, searchBar.text!))
    }

    tableView.reloadData()
}
}

extension SearchViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return searchResults.count
}

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

    let cellIdentifier = "SearchResultsCell"

    var cell: UITableViewCell! = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)

    if cell == nil {
        cell = UITableViewCell(style: .default, reuseIdentifier: cellIdentifier)
    }

    cell.textLabel?.text = searchResults[indexPath.row]
    return cell
}
}

我的控制台是空的

0 个答案:

没有答案
相关问题