Here you can see that I've set the delegate of my subclassed textView to itself:
import Foundation
class ImageCaptionTextView: UITextView, UITextViewDelegate {
override func awakeFromNib() {
super.awakeFromNib()
delegate = self
}
Now in my controller my delegate methods do not work. I'm using all the ImageCaptionTextView delegate methods in the ImageCaptionTextView subclass instead of where they previously were which was the controllers class.
Now there is some code I needed to add to the controller related textViewDidEndEditing delegate method for the ImageCaptionTextView but because the delegate method for the ImageCaptionTextView is set inside the ImageCaptionTextView subclass this new code added in controller won't work.
I'm starting to wonder whether I've just complicated things and should just move as much code as I can back into the controller. I just thought it made things a little cleaner for me.
So my question is:
How can I reference the ImageCaptionTextView's parent controller so instead of setting ImageCaptionTextView's delegate to itself i can set it to the controller?
Thanks for your time.
You could implement the delegate methods and then send the same message to the controller, but honestly that's naughty.
Consider doing everything you can in a controller using delegate methods before subclassing. If you hit something that the delegate methods won't handle, subclass, but change as little as possible with the view class implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With