ZhaZha
ZhaZha

Reputation: 67

change cell's backGroundColor from imagePickerController

Tell me pls how to change cell's backGroundColor from imagePickerController func:

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
}

Upvotes: 0

Views: 46

Answers (2)

Shruti Thombre
Shruti Thombre

Reputation: 988

You should try this :

let indexPath = IndexPath(item: 0, section: 0)
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! cellRegisterMarket
cell.backgroundColor = .red

Upvotes: 2

Shehata Gamal
Shehata Gamal

Reputation: 100541

Replace this

let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellRegisterMarket", for: indexPath) as! cellRegisterMarket

with

let cell = collectionView.cellForItem(at:indexPath) as! cellRegisterMarket

BTW this isn't a good way , update the model and reload the collection

Upvotes: 2

Related Questions