这是我的下载数据功能:
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
}
答案 0 :(得分:2)
在numberOfRowsInSection
中,值初始化为0.
传递给切换案例。它总是会出现默认值。因此numberOfRowsInSection
始终返回0
你的功能假设是这样的。
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var value = 0
if self.x == 1 {
value = suggestions.count
} else if self.y == 2 {
value = repairs.count
}
return value
}
答案 1 :(得分:1)
根据我的理解,您将根据x和y值有条件地绑定数据。您的numberOfRowsInSection
方法也应该反映出来。
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if x == 1 {
return suggestions.count
} else if y == 2 {
return repairs.count
}
return 0
}
希望它有所帮助。快乐编码!!