Swift Xcode TableViewCell's Not Loading First Time



我有一个按钮,它分段到我的TableViewController,当我第一次单击该按钮时,TableView不会加载,但当我返回并再次单击时,我的数据加载。

我试图设置断点,但表视图函数没有加载?有什么原因吗?

编辑:

这是我的TableView代码,如果需要任何其他代码,请告诉我。


class ServicesDisplay: UITableViewController {
@IBOutlet var MainTitle: UILabel!

@IBOutlet var image: UIImageView!
let db = Firestore.firestore()
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
myIndex = indexPath.row
performSegue(withIdentifier: "seque", sender: self)

}

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

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let jsonFbPic = (jsonFile["SecondScreen"])
let test = ((jsonFbPic["Services Image"]))
let count = ((test["Image(myIndex)"]))


if count.count == 0 {

return serviceTextArray.count

} else {

return count.count
}
}



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

cell.serviceText?.text = serviceTextArray[indexPath.row]

//Variables
let Json = jsonFile["SecondScreen"]
let MainTitleJson = Json["Text"]
let MainTitleSize = CGFloat(Int("(MainTitleJson["Size"])")!)
//Main Title:
cell.serviceText.font = UIFont(name: "(MainTitleJson["Font"])", size: MainTitleSize)
cell.serviceText.textColor = hexStringToUIColor(hex: "(MainTitleJson["Color"])")
cell.serviceImage?.loadImagesFromCacheWithUrlString(myIndex: indexPath.row, labelName: serviceTextArray[indexPath.row], CellImage: cell.serviceImage)
cell.selectionStyle = .none

return cell
}





public func hexStringToUIColor(hex: String) -> UIColor {
var cString: String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
var rgbValue: UInt64 = 0
if cString.hasPrefix("#") {
cString.remove(at: cString.startIndex)
} else if cString.count != 6 {
return UIColor.black
}
Scanner(string: cString).scanHexInt64(&rgbValue)
return UIColor(red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0, green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0, blue: CGFloat((rgbValue & 0x0000FF)) / 255.0, alpha: CGFloat(1.0))
}

override func viewDidLoad() {
super.viewDidLoad()


DispatchQueue.main.async(execute: { () -> Void in
self.tableView.reloadData()
})
}
override func viewDidAppear(_ animated: Bool) {

}


// MARK: - Table view data source



}

很抱歉将其作为答案发布,但我也是stackOverFlow的新手。之所以会发生这种情况,是因为您在从服务器获取数据之前执行segue。在数据提取完成后执行segue作为完成。如果是这样的话,请告诉我!

最新更新