IOS - working with large and growing UIViewController classes

I have a UIViewController that over time added many delegated events to it, which made the controller class quite large. The UIViewController class contains quite a few view control methods that are called from the event-delegate methods to control the UIView that controls the controller.

Now I add additional UIActionSheet command delegation events to the class. My controller class is getting big and I think I should split the UIActionSheet delegate events and put them in a separate delegate class. This separate delegate class would then have to be called back into the view controller class to force the view controller to adjust the view appropriately using the view control methods in the view controller. (The view controller refers to a separate model object that represents the view.)

I see the pros and cons for making this breakthrough. It is wrong to add more and more delegated events to the controller, but creating separate classes for different categories of events that then need to be called back into the controller also seems to create an unnecessary level of complexity and obfuscation. A large controller class is "simple and straightforward" but does not feel like that, while using many different delegate classes would be somewhat more complicated and involved, but would result in smaller classes.

Can anyone provide some words of wisdom on this topic, and perhaps point me to some iOS specific readings on the subject?

Many thanks.

+3


source to share


2 answers


In the end, I created quite a few additional classes to work with specific UIActionSheet instances. I created a base class and then subclassed it for each UIActionSheet requirement in the main controller.



The end result looks neat and doesn't add too much complexity.

0


source


My approach to this question:

  • Make it work.
  • Make a jib
  • Back to 1. (Or 1 and 2 in the same order if you have field experience)

So, if the application works well with the code, but you find that some classes have 100 methods, try different design patterns (if you don't already know) and use these ideas to create sections of code in different classes, delegates, encapsulate them if necessary ...

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaDesignPatterns/CocoaDesignPatterns.html

      



Anyway a link to Cocoa Suggestions a design template and I look into the Pro objective c design patterns for ios

. It may not be the best book, but it is based on The Gang of Four in an ios context.

Hope this helps at least somehow,

Greetings

0


source







All Articles