UITableViewCell показывает неправильное изображение и результат при поиске - PullRequest
0 голосов
/ 01 ноября 2019

Я пытаюсь использовать tableView с searchbar. Но когда я что-то ищу, он показывает неправильное изображение и результат. Я пытаюсь решить, но не могу.

Вот мой код:

let data = ["EN103052","EN103053","EN103055"]
let filedata = ["sample","sample","sample"]

var filteredData: [String]!

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "TableCell", for: indexPath) as? CellTableViewCell
    cell?.cellImage.image = UIImage(named: data[indexPath.row])
    return cell!
}

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

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 80
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let vc = storyboard?.instantiateViewController(withIdentifier: "PdfViewController") as? PdfViewController
    vc?.normTitle = data[indexPath.row]
    vc?.normFileName = filedata[indexPath.row]
    self.navigationController?.pushViewController(vc!, animated: true)
}

func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
    filteredData = searchText.isEmpty ? data : data.filter({ (item: String) -> Bool in
        return item.range(of: searchText, options: .caseInsensitive, range: nil, locale: nil) != nil
    })
    tableView.reloadData()
}

Я открыт для всех предложений.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...