从csv文件中提取数据放到UI表视图中。

问题描述 投票:-2回答:1

我想知道我是否可以问一个关于csvhttp发布的问题。我想在我从github csv文件中提取数据后,在我的应用程序中更新数据,但当我这样做时,它没有在应用程序中更新,只是打印数字。我的代码有什么问题?谢谢!我的代码有什么问题?

class NewStats.UITableViewController 类 NewStats: UITableViewController {

var didTapMenuType: ((NewMenu) -> Void)?

var Num2:String = "2"

@IBOutlet weak var MultnomahText: UILabel!

@IBOutlet weak var MultnomahView: UIProgressView!



override func viewDidLoad() {



                   let url = URL(string: "SampleUrl.csv")!

                   let task = URLSession.shared.dataTask(with: url) {(data, response, error) in

                   guard let data = data else { return }

                   let str = (String(data: data, encoding: .utf8)!)

                   let fullNameArr = str.components(separatedBy: ",")

                   let Num1    = fullNameArr[0]

                   self.Num2 = fullNameArr[1]

                   let Num3   = fullNameArr[2]

                   let Num4 = fullNameArr[3]

                   let Num5    = fullNameArr[4]

                   let Num6 = fullNameArr[5]

                   let Num7    = fullNameArr[6]

                   let Num8 = fullNameArr[7]

                   let Num9    = fullNameArr[8]

                   let Num10 = fullNameArr[9]



                   print(Num1);

                   print(self.Num2);

                   print(Num3);

                   print(Num4);

                   print(Num5);

                   print(Num6);

                   print(Num7);

                   print(Num8);

                   print(Num9);

                   print(Num10);







}

task.resume()

super.viewDidLoad()



DispatchQueue.main.async {

    self.tableView.reloadData()

}



print(self.Num2);



self.MultnomahText.text = "Multnomah:" + self.Num2

self.MultnomahView.setProgress(0.5, animated: true)



}
swift xcode csv url
1个回答
0
投票

在print(Num10)之后

DispatchQueue.main.async {
                       self.MultnomahText.text = "Multnomah:" + self.Num2
                       self.MultnomahView.setProgress(0.5, animated: true)
                       self.tableView.reloadData()
                       }

希望对大家有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.