uiviewcontroller - Object creation of views and share data between view in iOS -


i new ios.i stuck problem. have view , view b. view has navigation controller. view has button switch b.when clicking button every time b creates new object. how can track object share data between 2 view. thanks

there several ways this.

you have property of b, sets before push. (nsdictionary, array, string etc) not best way work.

uiviewcontroller *viewb = [[uiviewcontroller alloc]init]; [viewb setmyproperty:@"some data!"]; [self.navigationcontroller pushviewcontroller:viewb animated:yes]; 

you use nsnotificationcenter pass object next view.

nsdictionary *dictionary = [nsdictionary dictionarywithobject:                          [nsnumber numberwithint:index]                       forkey:@"index"];  [[nsnotificationcenter defaultcenter] postnotificationname:@"mynotification"                                       object:self                                       userinfo:dictionary]; 

the way handle setup , object holds data associated protocol initialized in appdelegate. view needs read/write grabs pointer object , runs it.

@class appdata;  @protocol appdataprotocol  - (appdata*)theappdata;  @end  

in view can grab pointer this.

-(appdata*)theappdata {      id<appdataprotocol> thedelegate = (id<appdataprotocol>)[uiapplication sharedapplication].delegate;     appdata* thedata = (appdata*)thedelegate.theappdata;      return thedata; } 

and this.

 appdata = [self theappdata]; 

you able access property of appdata.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -