iphone - Separating delegates from ViewController to own classes -


i'm pretty new ios development , i've become bit confused how should separate code avoid huge viewcontroller.m-file. main viewcontroller has quite many delegates:

@interface viewcontroller : uiviewcontroller <mkmapviewdelegate, httpclientdelegate, cllocationmanagerdelegate, nsfetchedresultscontrollerdelegate> 

i reduce viewcontroller code , guess should create separate classes handle delegate tasks. problem if example create singleton class cllocationmanager , let implement delegate methods, how communicate view controller?

let's cllocationmanager receives location update, how tell viewcontroller make changes ui? should use nsnotificationcenter post notification , add observer view controller? or best way let viewcontroller implement delegate methods now?

move of functionality data model.

it's hard how should manage given limited information you've provided, 1 has wonder whether single view controller should managing map view and keeping track of location and managing http connection and managing core data fetch. why not move of model, it'll easier divide modules?

let's cllocationmanager receives location update, how tell viewcontroller make changes ui? should use nsnotificationcenter post notification , add observer view controller?

a notification solution -- provides way part of program manages location (again, belongs in model) communicate change without having know in particular parts of program care changes location. allows one-to-many communication -- if have view controller cares location, can observe same notification.

or best way let viewcontroller implement delegate methods now?

i try think dividing responsibilities appropriately more limiting size of code. if have class 1 job needs lot of code it, that's fine. if have 1 class manages many unrelated things, that's not good. trouble lot of jobs seem fall traditional "manages screenful of content" role of view controller. try separate task of managing presentation of data (which view controller's rightful job) managing data (which model's job).


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -