uiviewcontroller - iOS - sharing data amongst ViewControllers -


i have 2 viewcontrollers purpose of landscape orientation

my first vc (portraitvc) has multiple uitextfields (about 30 of them) i'm using nsnotifications observe when interface orientation changes , when pushes viewcontroller on screen (specific landscape)

my question is, possible share uitexfields amongst both vc's if enter in portrait when go landscape mode don't lose text entered on textfield: , should work other way around too

you're or guide appreciated

i can think of couple ways handle this.

first, reconsider choice use 2 different vcs handle orientation changes. how hard update ui on first vc appropriate in portrait?

second, abstract data out struct or class can pass , forth between 2 vcs

@interface mydatastorage : nsobject {     nsstring* text1;     nsstring* text2;     nsstring* text3;     nsstring* text4; } 

lastly, create protocol keep 2 vcs in sync:

@protocol vcsync : nsobject { - (void)updatetextbox1:(nsstring*)contents; - (void)updatetextbox2:(nsstring*)contents; ... } 

you need keep references other vc can call appropriate method textbox delegate callbacks.

re: documentation link

if you're referencing passage: there better ways provide unique views different orientations, such presenting new view controller should read previous sentence.

a new vc suggested if you're swapping out entire view hierarchy. if resizing textboxes write code in willanimaterotationtointerfaceorientation:duration: since won't have move of information 1 vc another.

if still decide go ahead vc create class contains bunch of nsstrings or nsattributedstrings needs dictate. need method on each of vcs goes like:

- (void)updatetextboxeswithdata:(mydatastorage*)data {     for(uitextbox in self.textboxes) {         t.text = data.string;     } } 

Comments

Popular posts from this blog

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

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

javascript - storing input from prompt in array and displaying the array -