gpt4 book ai didi

ios - cellForRowAt 索引路径函数未调用

转载 作者:行者123 更新时间:2023-11-30 11:31:39 24 4
gpt4 key购买 nike

当我尝试运行代码时,cellForRowAtIndexPath 函数由于某种原因无法运行。

numberOfSections 函数运行良好。我认为这是 dataSource/delegate 函数或单元格的问题。

非常感谢找到此问题的解决方案。

import UIKit

class MoviesTableViewController: UITableViewController {
@IBOutlet weak var searchBar: UISearchBar!


override func viewDidLoad() {
super.viewDidLoad()

tableView.delegate = self
tableView.dataSource = self


MovieController.getAllMovies(name: "blue") { (sucess) in
if sucess {
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}
tableView.reloadData()
}

override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return MovieController.movies.count
}

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


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "movieCell", for: indexPath) as! MoviesTableViewCell

let movie = MovieController.movies[indexPath.row]

cell.movieRating.text = String(movie.vote_average)
cell.movieRating.text = movie.overview
cell.movieTitle.text = movie.title

return cell
}

最佳答案

打印调试

override func numberOfSections(in tableView: UITableView) -> Int {
print("Number of section called")
return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("Number of rows in section called")
print("Movies count: ", MovieController.movies.count)
return MovieController.movies.count
}

如果调用的节数未打印到控制台:您的tableView有问题,它是DataSource

else if Movies Count: 0: tableView 数据源运行良好,这是您的 MoviewController.movi​​es 问题。检查您的MovieController

对于下一步,我需要查看 MoviewController 内容。

关于ios - cellForRowAt 索引路径函数未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50196175/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com