从 uiimagePickerController 更改单元格背景颜色
change cell's backGroundColor from imagePickerController
请告诉我如何从 imagePickerController 函数更改单元格的 backGroundColor
:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
self.dismiss(animated: true, completion: nil)
//let imageUser = info[UIImagePickerController.InfoKey.editedImage] as! UIImage
let indexPath = IndexPath(item: 0, section: 0)
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellRegisterMarket", for: indexPath) as! cellRegisterMarket
cell.backgroundColor = .red
}
替换这个
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellRegisterMarket", for: indexPath) as! cellRegisterMarket
和
let cell = collectionView.cellForItem(at:indexPath) as! cellRegisterMarket
顺便说一句,这不是一个好方法,请更新模型并重新加载集合
你应该试试这个:
let indexPath = IndexPath(item: 0, section: 0)
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! cellRegisterMarket
cell.backgroundColor = .red
请告诉我如何从 imagePickerController 函数更改单元格的 backGroundColor
:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
self.dismiss(animated: true, completion: nil)
//let imageUser = info[UIImagePickerController.InfoKey.editedImage] as! UIImage
let indexPath = IndexPath(item: 0, section: 0)
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellRegisterMarket", for: indexPath) as! cellRegisterMarket
cell.backgroundColor = .red
}
替换这个
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellRegisterMarket", for: indexPath) as! cellRegisterMarket
和
let cell = collectionView.cellForItem(at:indexPath) as! cellRegisterMarket
顺便说一句,这不是一个好方法,请更新模型并重新加载集合
你应该试试这个:
let indexPath = IndexPath(item: 0, section: 0)
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! cellRegisterMarket
cell.backgroundColor = .red