EFColorPicker icon indicating copy to clipboard operation
EFColorPicker copied to clipboard

Problems with delegate

Open KursX opened this issue 6 years ago • 2 comments

func colorViewController(_ colorViewCntroller: EFColorSelectionViewController, didChangeColor color: UIColor) does not work.

Because here: self.delegate?.colorViewController(self, didChangeColor: color)

self.delegate always nil, despite that I set it

I fixed this by deleting weak here:

public WEAK var delegate: EFColorSelectionViewControllerDelegate?

Maybe I did something wrong?

KursX avatar Jan 13 '20 21:01 KursX

Probably something wrong, the delegate pattern is usually used with weak references in order to avoid a reference cycle

You are probably getting rid of the delegate object after presenting the EFColorPicker (and likely causing a memory leak in your program)

How are you setting the delegate? It is a view controller? Does the program retains it after presenting the color picker?

ebarellar avatar Jan 13 '20 22:01 ebarellar

func show(controller: SettingsViewController) {
    let navCtrl = UINavigationController(rootViewController: colorSelectionController)
    navCtrl.navigationBar.backgroundColor = UIColor.white
    navCtrl.navigationBar.isTranslucent = false
    navCtrl.modalPresentationStyle = UIModalPresentationStyle.popover
    navCtrl.popoverPresentationController?.delegate = controller
}

KursX avatar Mar 04 '20 15:03 KursX