我想用一个按钮更改用于创建所有单元格的整个数组,然后重新加载我的集合视图,但是它不起作用。我试图将集合视图重新加载到主线程中,但它也无法正常工作
我试图将集合视图重新加载到主线程中,或者仅使用collectionView.reloadData()但它也无法正常工作
@IBAction func BicepsBtn(_ sender: Any) {
self.current = "Biceps"
Data = user.getMuscleDataChart(typeMuscle: current)
listMuscle = user.getListMuscle(typeMuscle: current)
collectionView.reloadData()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return listMuscle.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
let switchView = cell.viewWithTag(1000) as? UISwitch
let titleView = cell.viewWithTag(1001) as? UILabel
if let titleView = titleView, let switchView = switchView {
titleView.text = self.listMuscle[indexPath.row].label
titleView.textColor = self.listMuscle[indexPath.row].color
switchView.tag = indexPath.row
switchView.addTarget(self, action: #selector(yourFunc),
for: UIControl.Event.valueChanged)
}
return cell
}
这是我当前的代码,当用户单击“二头肌”按钮时,该功能将获取有关该肌肉的所有数据,然后尝试重新加载。 任何想法 ? 预先感谢