我在表格視圖中介紹和修復了x等於1時的數據會被引入到數據中,等於2會被轉移到修復數據中,但是當我在執行後是空白的表視圖,以及我的委託和數據源是有一個環節加載表格視圖數據
這裏是我的下載數據功能:
func laodingTableviewData() {
self.suggestionTableView.isHidden = true
let frame = CGRect(x: 150, y: 283, width: 80, height: 80)
let color = UIColor(red: 50.0/255.0, green: 124.0/255.0, blue: 203.0/255.0, alpha: 1)
let activityIndicatorView = NVActivityIndicatorView(frame: frame, type: .ballSpinFadeLoader, color: color, padding: 20)
self.view.addSubview(activityIndicatorView)
activityIndicatorView.startAnimating()
if self.x == 1 {
DispatchQueue.main.async {
print("Start download suggestion data...")
self.suggestions = Suggestion.downloadAllSuggestion()
self.suggestionTableView.isHidden = false
self.suggestionTableView.reloadData()
}
} else if self.y == 2 {
DispatchQueue.main.async {
print("Start download repair data...")
self.repairs = Repair.downloadAllRepair()
self.suggestionTableView.isHidden = false
self.suggestionTableView.reloadData()
}
}
activityIndicatorView.stopAnimating()
}
我在self.suggestions = advice.downloadAllSuggestion()
設置斷點,我相信一定有被抓住的數據,但無法在表格視圖中顯示,請幫忙解答,謝謝!
下面是表視圖函數
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "mycell", for: indexPath) as! FirstTableViewCell
if x == 1 {
cell.suggestions = suggestions[indexPath.row]
} else if y == 2 {
cell.repairs = repairs[indexPath.row]
}
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var value = 0
switch value {
case self.x:
value = suggestions.count
case self.y:
value = repairs.count
default:
break
}
return value
}
添加代碼的cellForRowAtIndexPath&numberRowsInSection方法 – Subramanian
錯流肯定的,'downloadAllSuggestion()'可能是異步的,這意味着'reloadData()'下載完成之前被調用,導致你的表視圖犯規更新 – Tj3n
@ Tj3n那請問不正確,因爲異步方法不應該有返回類型。我也對'Suggestion.downloadAllSuggestion()'裏面的東西感到困惑' –