Guidance required on View Hierarchy and Delegation

Hi. I’m currently working on my largest app to date. I’ve been guilty of using Massive View Controllers in the past and I’m working hard to keep everything re-usable where possible and to not repeat my code. In this example I feel I’m complicating matters and there must be a more elegant solution.

My query relates to a subclass of UITextField. I have a ‘Card’ view, which contains a ‘Ticket’ subview, and the ticket has a UITextField amongst other things. My model object item is within the card view. The card view is specific for its purpose. The ticket and textfield are generic and can be used throughout the project. I need to point the UITextFieldDelegate ‘DidEndEditing’ back at the Card view which will them update the model object.

How would I be best to do this? Subclass my textfield again and amend the delegate method? Create a whole new delegate class with this method changed [feels wrong to rewrite all of the other delegate methods again], or create my own delegate method and use that within the subclass for all textfields in my project? Or another answer altogether?

I ask because to me the simple answer is to subclass the textfield and override the one method. Having previously read that subclassing isn’t recommended I’m trying to learn what’s best and become a better developer.

Any advice is greatly appreciated. Thanks, Steve

@ste23 Do you still have issues with this?

This topic was automatically closed after 166 days. New replies are no longer allowed.