iphone - How to access data from ViewController in subview? -


i have viewcontroller contains instance variable containing dictionary object bunch of data. view complex , contains several subviews instantiate , embed seperate view files(to avoid having thousand lines of ui code in actual viewcontroller) - how these subviews, exists in own files, access dictionary object viewcontroller? when im editing descriptionview.m file - how access contents of locationdata dictionary object viewcontroller?

hope understand mean.

here's snippet viewcontroller:

caseviewcontroller.h

#import "descriptionview.h"  @interface caseviewcontroller : uiviewcontroller {     nsdictionary *locationdata;      descriptionview *descriptionview; }  @property (nonatomic, retain) nsdictionary *locationdata; @property (nonatomic, retain) descriptionview *descriptionview;  @end 

caseviewcontroller.m

- (void)loadview {     uiview *view = [[uiview alloc] init];      descriptionview = [[descriptionview alloc] initwithframe:cgrectmake(0, 130, 320, 237)];     descriptionview.hidden = no;      [view addsubview:descriptionview];      self.view = view;     [view release]; } 

ideally should never access properties of viewcontroller view. main idea of mvc architecture viewcontroller tells it's views render , not vise versa. have provide data view needs rendering during it's initialization:

- (void)loadview {      uiview *view = [[uiview alloc] init];      descriptionview = [[descriptionview alloc] initwithframe:cgrectmake(0, 130, 320, 237) paramdict: self.locationdata]; descriptionview.hidden = no;      [view addsubview:descriptionview];      [descriptionview release]; // btw add line here (or in dealloc) or you'll have leak      self.view = view; [view release];  } 

if need update view dynamically, should add methods view , call them viewcolnroller. e.g.:

descriptionview.m:

-(void) updatewithdict:(nsdictionary*) udict; 

if need perform actions when button in descriptionview pressed (or other user interaction) idea declaring protocol descriptionviewdelegate (or smth that):

-(void) descriptionviewbutton1pressed:(descriptionview*) dview; -(void) descriptionviewbutton2pressed:(descriptionview*) dview; 

then make caseviewcontroller delegate , implement methods there.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -