objective c - how to slim down view controllers in iOS? -
how guys slim down view controllers?, end implementing lot of protocols in view controller, there’s lot of code inside controller itself. reading how slim down view controllers in ios found common way move datasources (http://www.objc.io/issue-1/lighter-view-controllers.html) other class, other delegates?, or if create views code?. first, think move each delegate nsobject class, try this:
self.locationmanager.delegate = [[frrypetdescriptionviewcontrollerlocationdelegate alloc] init];
then ask in irc , suggest categories, got far:
// frrypetdescriptionviewcontroller.h @interface frrypetdescriptionviewcontroller : uiviewcontroller @property (nonatomic) cllocationmanager *locationmanager; @property (nonatomic) tpkeyboardavoidingscrollview *scrollview; @property (nonatomic) uiview *contentview; @end // frrypetdescriptionviewcontroller+protocols.h @interface frrypetdescriptionviewcontroller (protocols) <uitextviewdelegate, uiactionsheetdelegate, mfmailcomposeviewcontrollerdelegate, uigesturerecognizerdelegate, mkmapviewdelegate, uiviewcontrollertransitioningdelegate, cllocationmanagerdelegate> @end // frrypetdescriptionviewcontroller+uiadditions.h @interface frrypetdescriptionviewcontroller (uiadditions) - (void)createscrollview; - (void)createcontentview; @end // frrypetdescriptionviewcontroller+callbacks.h @interface frrypetdescriptionviewcontroller (callbacks) @end // frrypetdescriptionviewcontroller+locationadditions.h @interface frrypetdescriptionviewcontroller (locationadditions) @end
this makes me think, “private” methods?, need declare properties in view controller header file?. guys think approach or there’s common pattern follow not end fat controller?.
thank you.
the link have referred has beautiful explanation less bulky controller's programming. techniques bit tricky unless seasoned developer. have asked multiple techniques in question. please check views on them below: -
delegates - prefer keep delegate code in controller avoid unwanted confusion specially when working multiple scenarios within same controller.
create views programmatically - portion can cut large amount of code uiviewcontroller. unless single control such single label or button, should make custom uiview class , let set common properties view customisation. controller should invoke necessary parameters.
properties in header file - no, concept of data encapsulation says should make variables public required. rest should move private domain external objects can't interfere class object functionality. should declare these properties in class extension (inside .m file). not required have variables properties, when private can declare them instance variables property declaration nothing create getter/setter variable.
private methods - same goes methods well. if doesn't have exposed other objects; should not in header file. keep in extention private method.
Comments
Post a Comment