ios - 从 viewDidLoad 中调用的函数外部重新加载 UITableViewController

标签 ios swift uitableview reloaddata

<分区>

我正在使用 UITableViewController 并且需要在函数中重新加载表。当我运行该应用程序时,表格 View 没有重新加载。我没有收到任何错误。

代码:

func loadTheaters() {

    let api = ""
    let theaterId = id
    let date = date
    let url = URL(string: "http://data.tmsapi.com/v1.1/theatres/\(theaterId)/showings?startDate=\(date)&api_key=\(api)")
    print(url!)
    let request = URLRequest(
        url: url! as URL,
        cachePolicy: URLRequest.CachePolicy.reloadIgnoringLocalCacheData,
        timeoutInterval: 10 )

    let session = URLSession (
        configuration: URLSessionConfiguration.default,
        delegate: nil,
        delegateQueue: OperationQueue.main
    )

    let task = session.dataTask(with: request, completionHandler: { (dataOrNil, response, error) in
        if let data = dataOrNil {
            do { let filmList = try! JSONDecoder().decode([Films].self, from: data)
                self.films = filmList
                self.tableView.reloadData()
            }
        }
    })
    task.resume()
}

为什么 tableview 没有重新加载?

最佳答案

我已将 numberOfSections 返回到 0。

已解决:

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

关于ios - 从 viewDidLoad 中调用的函数外部重新加载 UITableViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53789370/

相关文章:

ios - AFNetworking - NSMutableDictionary 参数

ios - Objective-C . 如果文本字段等于某物,我希望标签显示特定文本

c++ - Cocos2Dx "use of undeclared identifier"iOS游戏内购

swift - 动态 NSTooltips : Event Key Modifier(s) Affecting Tooltips

ios - 带有约束的标签添加到具有纵横比的 ImageView

objective-c - 确保单元格中的内容不会被错误地重复使用的最有效方法是什么

ios - 如何创建复制弹出窗口?

ios - collectionView 中的异常(_ :layout:sizeForItemAt:) when accessing layout. collectionViewContentSize

swift - CAShapeLayer。旋转框架坐标更新后,但路径坐标没有更新

ios - 如何在带有协议(protocol)的 UITableView 中拥有多个 UITableViewCell 原型(prototype)?