Post

Replies

Boosts

Views

Activity

Comment on [Swift] How to properly subclass UITextfield and work with its delegate
@Claude31 I fixed the init() stuff, it's working now. It wasn't working before because I had the ViewController code which uses MyTextField to also have a UITextFieldDelegate: class ViewController: UIViewController, UITextFieldDelegate { override func viewDidLoad() { let myTF = MyTextField( .... ) myTF.delegate = self }    func textFieldDidBeginEditing(_ textField: UITextField) {     print("XXXXX"). // This is printed instead of "Inside subclassed textfield" within the subclass.   }  ``` So, if the subclassed textfield's delegate is set to self within the calling code (ViewController in this case), the textFieldDidBeginEditing() inside the subclass is never called. In general, is there a way to trigger textFieldDidBeginEditing() in both the calling code as well as the one inside the subclass?
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’21
Comment on How to link an App project to a Framework project so that changes made to the Framework code are "seen" in the App code without explicitly building the Framework code in Terminal?
@edford Thank you. Took me a while to zero in on the right section of that article, but I got it to work.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Comment on [Swift] How to properly subclass UITextfield and work with its delegate
@Claude31 Thanks for your explanation. It seems to me that, in general, when a subclass makes use of the delegate, it runs the risk of having the calling code hijack the functionality of the subclass either deliberately or unintentionally by also using the delegate. Something to be mindful of.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Comment on [Swift] How to properly subclass UITextfield and work with its delegate
Oops, sorry, I didn't know formatting is off inside a comment!
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Comment on [Swift] How to properly subclass UITextfield and work with its delegate
@Claude31 I fixed the init() stuff, it's working now. It wasn't working before because I had the ViewController code which uses MyTextField to also have a UITextFieldDelegate: class ViewController: UIViewController, UITextFieldDelegate { override func viewDidLoad() { let myTF = MyTextField( .... ) myTF.delegate = self }    func textFieldDidBeginEditing(_ textField: UITextField) {     print("XXXXX"). // This is printed instead of "Inside subclassed textfield" within the subclass.   }  ``` So, if the subclassed textfield's delegate is set to self within the calling code (ViewController in this case), the textFieldDidBeginEditing() inside the subclass is never called. In general, is there a way to trigger textFieldDidBeginEditing() in both the calling code as well as the one inside the subclass?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21