ios - How to share array of data from container/parent view controller and multiple children view controllers -
i have scenario there parent container view controller subview taking of screen. subview used swap out 3 different views of same info (a map, table , gallery). there segmented command used select view of info user wants view. have array collection of model type in parent container view controller , have these 3 different kid view controllers each display info in respective views. there clean way without having duplicate info 4 times (once in parent , 3x in children)? i'm assuming have duplicate data, because kid should not able phone call parent view controller access array. it's not appropriate inheritance situation, since parent more of container same type of view controller. it's not delegate situation, because children don't need notify parent of anything, other way around.
any suggestions appreciated.
thanks.
i create class (mydatacontroller below) manage data, , utilize shared instance access anywhere in app.
interface (mydatacontroller.h)
@interface mydatacontroller : nsobject { nsmutablearray *mydata; // collection need share } + (mydatacontroller*)shareddatacontroller; // ... add together functions here read / write info @end
implementation (mydatacontroller.m)
static mydatacontroller* shareddatacontroller; // unique , contain info @implementation mydatacontroller + (mydatacontroller*)shareddatacontroller { if (!shareddatacontroller) shareddatacontroller = [[[mydatacontroller alloc] init] autorelease]; // no autorelease if arc homecoming shareddatacontroller; } // ... implement functions read/write info @end
finally, access static object anywhere:
mydatacontroller *datacontroller = [mydatacontroller shareddatacontroller]; // create or homecoming existing controller;
ios objective-c uiviewcontroller
No comments:
Post a Comment