У меня есть searchController, получающий данные из Google Places API.Я использую UITableView для заполнения ячеек, однако они не заполняются (я полагаю, из-за вышеуказанной ошибки)
- У меня есть все настроенные делегаты
- TableViewперезагрузка данных
- Запрос печатается в консоли, как и ожидалось
Из того, что я прочитал на S / OF, это может быть связано с регистрацией ячейки - см.код ниже
TableView
func configureTableView() {
tableView.delegate = self
tableView.dataSource = self
view.addSubview(tableView)
tableView.anchor(top: view.topAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor,
paddingTop: 0, paddingLeft: 0, paddingBottom: 0, paddingRight: 0,
width: 0, height: 0)
tableView.tableFooterView = UIView()
tableView.register(UITableViewCell.self, forCellReuseIdentifier: recentSearchesCellIdentifier)
tableView.register(ResultsCell.self, forCellReuseIdentifier: searchResultsCellIdentifier)
tableView.keyboardDismissMode = .interactive
tableView.backgroundColor = UIColor(red: 242/255, green: 242/255, blue: 243/255, alpha: 1)
}
CellForItemAtIndexPath
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let recentSearchesCell = tableView.dequeueReusableCell(withIdentifier: recentSearchesCellIdentifier, for: indexPath)
let searchResultsCell = tableView.dequeueReusableCell(withIdentifier: searchResultsCellIdentifier, for: indexPath) as! ResultsCell
switch sections[indexPath.section].section {
case .RecentSearches:
recentSearchesCell.selectionStyle = .none
let recentSearches = recentResults[indexPath.row]
recentSearchesCell.textLabel?.text = recentSearches
recentSearchesCell.detailTextLabel?.text = recentSearches
return recentSearchesCell
case .SearchResults:
searchResultsCell.selectionStyle = .none
let result = searchResults[indexPath.row]
searchResultsCell.result = result
return searchResultsCell
}
}
Ячейка
class ResultsCell: UITableViewCell {
var result: GMSAutocompletePrediction? {
didSet {
self.textLabel?.attributedText = result?.attributedPrimaryText
self.detailTextLabel?.attributedText = result?.attributedSecondaryText
}
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}