У меня есть UITableView внутри UIScrollView. У UITableView отключена прокрутка и есть все необходимые delgates внутри ViewController (как можно увидеть в приведенном ниже коде). Однако, когда я щелкаю элемент в таблице, didSelectRowAt никогда не вызывается (didHighlightRowAt также никогда не вызывается). Почему не называется? Как это исправить?
class NewsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
private static let headlineArticleReuseIdentifier = "HeadlineArticleCell"
private static let categoryCellReuseIdentifier = "NewsCategoryCell"
@IBOutlet weak var headlineArticlesPreviewList: UITableView!
private var bindings = Set<AnyCancellable>()
private var viewModel: NewsViewModel = NewsViewModel()
private var headlineArticles: [Article] = []
@IBOutlet weak var headlineTitle: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.navigationController?.setNavigationBarHidden(true, animated: false)
headlineArticlesPreviewList.delegate = self
headlineArticlesPreviewList.dataSource = self
let cancellable = viewModel.$viewState.sink(receiveValue: { state in
switch state {
case let .data(data):
self.setData(data: data)
print()
case let .error(error):
print(error)
case .loading:
print()
}
})
bindings.insert(cancellable)
}
private func setData(data: NewsViewModel.ViewState.Data) {
self.headlineArticles = data.headlineArticles
self.headlineTitle.text = data.headlineCategory.displayName
self.headlineArticlesPreviewList.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return headlineArticles.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = headlineArticlesPreviewList.dequeueReusableCell(
withIdentifier: NewsViewController.headlineArticleReuseIdentifier,
for: indexPath)
as? HeadlineArticleTableViewCell else {
fatalError("could not cast to headline article")
}
let headlineArticle = headlineArticles[indexPath.item]
cell.setArticle(article: headlineArticle)
return cell
}
func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
print()
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "HeadlineArticleSegue", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "HeadlineArticleSegue" {
let detailViewController = segue.destination
as! ArticleViewController
let articleIndexPath = headlineArticlesPreviewList.indexPathForSelectedRow!
let row = articleIndexPath.row
detailViewController.article = headlineArticles[row]
}
}
}
Настройки UITableView

UITableView Inside UIScrollView

UITableViewCell Settings
введите описание изображения здесь