[英]Swift Xcode TableViewCell's Not Loading First Time
I have a Button which Segues to my TableViewController
and when I click the button for the first time, the TableView Doesn't Load but when I go back and click again, my Data Loads.我有一个与TableViewController
的按钮,当我第一次单击该按钮时,TableView 不会加载,但是当我返回并再次单击时,我的数据会加载。
I tried to set the breakpoints but the tableview functions don't load?我试图设置断点但 tableview 函数没有加载? Any reason for this?这有什么原因吗?
EDIT:编辑:
This is my Code For The TableView, if any other code is required tell me.这是我的 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
}
Sorry for posting it as an answer but I am also new to stackOverFlow.很抱歉将其发布为答案,但我也是 stackOverFlow 的新手。 It Is happening because you are performing segue before the data is fetched from the server.这是因为您在从服务器获取数据之前执行 segue。 Perform segue as a completion after data fetch is completed.在数据获取完成后执行 segue 作为完成。 Please let me know if that was a case!如果是这种情况,请告诉我!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.