Ios 在TableView中显示数组中的数据在swift 3中不起作用?

Ios 在TableView中显示数组中的数据在swift 3中不起作用?,ios,arrays,json,uitableview,swift3,Ios,Arrays,Json,Uitableview,Swift3,我试图在swift 3中将数组中的一些数据显示到tableView中。 我创建了两个控制器,一个名为TableViewCell的控制器声明了标签,另一个控制器具有该函数 class FlightContro: UIViewController, UITableViewDataSource, UITableViewDelegate { var fetchDetails = [Details]() @IBOutlet weak var tableView: UITableView

我试图在swift 3中将数组中的一些数据显示到tableView中。 我创建了两个控制器,一个名为TableViewCell的控制器声明了标签,另一个控制器具有该函数

class FlightContro: UIViewController, UITableViewDataSource, UITableViewDelegate {

    var fetchDetails = [Details]()

    @IBOutlet weak var tableView: UITableView!

    var allFlightsArray = [AnyObject]()
    var carrierArray = [String]()




    override func viewDidLoad() {
        super.viewDidLoad()
        parseData()
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

     // API 
    func parseData(){
        fetchDetails = []
        let urlString = "APIURL"
        var request = URLRequest(url: URL(string: urlString)!)
        request.httpMethod = "GET"

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

        let task = session.dataTask(with: request) { ( data,response, error) in
            if(error != nil){
                print("Error")
            }else{
                do{
                    let fetchedData = try JSONSerialization.jsonObject(with: data!, options: .mutableLeaves) as! NSDictionary

                    for index in 0...data.count-1 {
                        let aObject = data[index] as! [String : AnyObject]
                        let aObject1 = aObject["data"] as! [String : AnyObject]
                        let category = aObject1["category"] as! String
                        let aObject2 = aObject1["flightInfo"] as! [String : AnyObject]



                        self.allFlightsArray.append(aObject2 as! AnyObject)


                    }


                    for flight in self.allFlightsArray{

                        self.carrierArray.append(flight["flightCarrier"] as! String)
 }

                    print(self.carrierArray)
                    OperationQueue.main.addOperation({
                        self.tableView.reloadData()
                    })


                } catch{
                    print ("Error 2")
                }
            }

    }
        task.resume()


}

func numberOfSectionsInTableView(tableView: UITableView) -> Int{
        return 1
    }

func  tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell
        cell.destination.text = "text"
        return cell
    }


}
这是我的主控制器 导入UIKit

class TableViewCell: UITableViewCell {


    @IBOutlet weak var destination: UILabel!
    @IBOutlet weak var company: UILabel!
    @IBOutlet weak var location: UILabel!
    @IBOutlet weak var time: UILabel!
    @IBOutlet weak var terminal: UILabel!


    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
    }

}

打印API中的所有数据效果很好,但我无法在表视图中显示它,我尝试了很多次,但都不起作用。

也添加UITableViewDelegate
cell.destination.text=“text”
您根本不使用
allFlightsArray
carrierArray
?是否调用了
tableView(\tableView:UITableView,numberofrowsinssection:Int)
?tableView的数据源/委托在哪里设置?numberOfRowsInSection返回10,func tableView(uTableView:UITableView,numberOfRowsInSection:Int)->Int{return 10}cell.destination.text=“text”用于测试是否工作,我使用cell.destination.text=self.carrierary[indexPath.row]但是不起作用了为什么要先将
aoobject2
转换到字典,然后再转换到(更未指定的)
任何对象
?在这种情况下,向上投射是相当愚蠢的。顺便说一下,无论如何不要在Swift中使用
NSDictionary
。除此之外,Swift 3中的JSON字典是
[String:Any]
。不要在动态表视图中硬编码
numberOfRows…
。因为JSON的格式不正确,所以强制转换AOObject2实际上可以让我获得所需的正确数据。NSDictionary目前不起任何作用,我可以稍后更改它。。我已经在函数中做了更改,所以现在调用array.count。。。这里有什么问题?似乎仍不起作用..是否也添加UITableViewDelegate
cell.destination.text=“text”
您根本不使用
allFlightsArray
carrieray
?是否调用了
tableView(\tableView:UITableView,numberofrowsinssection:Int)
?tableView的数据源/委托在哪里设置?numberOfRowsInSection返回10,func tableView(uTableView:UITableView,numberOfRowsInSection:Int)->Int{return 10}cell.destination.text=“text”用于测试是否工作,我使用cell.destination.text=self.carrierary[indexPath.row]但是不起作用了为什么要先将
aoobject2
转换到字典,然后再转换到(更未指定的)
任何对象
?在这种情况下,向上投射是相当愚蠢的。顺便说一下,无论如何不要在Swift中使用
NSDictionary
。除此之外,Swift 3中的JSON字典是
[String:Any]
。不要在动态表视图中硬编码
numberOfRows…
。因为JSON的格式不正确,所以强制转换AOObject2实际上可以让我获得所需的正确数据。NSDictionary目前不起任何作用,我可以稍后更改它。。我已经在函数中做了更改,所以现在调用array.count。。。这里有什么问题?好像还是不起作用。。