Wednesday, 15 April 2015

ios - How should I be transferring data through multiple view controllers? -



ios - How should I be transferring data through multiple view controllers? -

passing info between view controllers in ios development seems overly complicated. here i've come realize: passing info forwards (pushing view) or straight segueing view can done -(void)prepareforsegue method. info can shuffle , forth between view controllers using presentingviewcotnroller , presendedviewcontroller properties. here illustration of info going sec view controller first view controller. here illustration code of i'm talking about:

((firstviewcontroller *)self.presentingviewcontroller).firstviewcontrollerproperty = self.secondviewcontrollerproperty;

however i'm stuck when trying pass info through multiple view controllers. seems utilize delegation , think in terms of mvc. when effort stuck. here why: if viewcontrollera tells model hold info , viewcontrollerd needs info end having viewcontrollerd reference instance of model. (i b/c don't how else access model view controller) i'm assuming when create instance of model, mean have fresh model without info trying access.

then realize maybe should setting model singleton. i'm assuming singletons when set 1 class referenced other view controllers without them having create instances of model class. more read singletons more sense i'm getting off track. seek putting these things , gets overly complicated.

am missing here? should able reference model various view controllers without creating new instances of it? i'm relatively new ios programming, , i'm looking point me in right direction. should putting energy learning delegation? or learning singletons? or learning target actions? there easy tutorial / book recommendation larn transferring info among view controllers?

if want easiest way, add together property view controller , when want pass info view controller, set property info trying pass. way create method on view controller take data, , calling code phone call method on view controller info want send.

as long have reference controller want pass info to, can set properties or phone call methods needed.

don't confused delegates, way provide interface communication using methods. essential understand delegates in ios development, since used heavily.

read on objective-c protocols, similar interfaces in other languages. delegates phone call objects implement protocol.

only pass info necessary know previous view controller. don't need pass info store each time force view controller, force id of object you're working on or variables new view need job. view controllers should able access info store independently of each other, don't pass around info fetched info store.

ios model-view-controller uiviewcontroller delegation

No comments:

Post a Comment