L1GhTUA L1GhTUA - 10 months ago 63
iOS Question

TableView displaying cells uncorrectly

Have a property

var resultSearchController = UISearchController()

Creating UISearchController on viewDidLoad() method

self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.barStyle = UIBarStyle.black
controller.searchBar.barTintColor = UIColor.white
controller.searchBar.backgroundColor = UIColor.clear
controller.hidesNavigationBarDuringPresentation = false
self.tableView.tableHeaderView = controller.searchBar
return controller

As result have a note text with normal displaying plus and particularly displaying a start on text on left top corner of each cell.
What could i do wrong?
P.S. Figured out most likely it have nothing to do with UISearchBar

enter image description here

Answer Source

I found the lines i made a mistake. I used property cell.textLabel instead of cell.noteLabel. Ty for your time.

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cellIdentifier = "NoteTableViewCell"

    let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! NoteTableViewCell
    let note: Note
    if self.resultSearchController.isActive {
        note = filteredNotes[indexPath.row]
        cell.textLabel?.text = filteredNotes[indexPath.row].note
    } else {
        note = notes[indexPath.row]
        cell.textLabel?.text = notes[indexPath.row].note

    return cell