Wednesday 15 January 2014

ios - Accessing subview variables from another subview -



ios - Accessing subview variables from another subview -

i have uiviewcontroller 2 sub uiviews. in first uiview created uiview greenish background. after pushing button in uiviewcontroller alter reddish background.

and want alter violet background, since changed background in uiviewcontroller i'm not able alter (again).

uiviewa.h

@interface uiviewa : uiview @property uiview *colorview;

uiviewa.m

... colorview = [[uiview alloc]init]; [colorview setbackgroundcolor:[uicolor greencolor]]; ...

uiviewcontroller.h

#import "uiviewa.h" #import "uiviewb.h" @interface mainviewcontroller : uiviewcontroller @property uiviewa *viewa; @property uiviewb *viewb;

uiviewcontroller.m

... viewa = [[uiviewa alloc]init]; viewb = [[uiviewb alloc]init]; ... -(void)changecolor { [[viewa colorview] setbackgroundcolor:[uicolor redcolor]]; }

uiviewb.h

#import "uiviewa.h" @interface uiviewb : uiview @property uiviewa *viewa;

uiviewb.m

... viewa = [[uiviewa alloc]init]; [[viewa colorview] setbackgroundcolor:[uicolor greencolor]]; // ^^ rule doesn't seem work. no errors given. ...

edit: shorter illustration of i'm trying do.

if understand right, want alter viewa's background color in viewb. can in viewcontroller.m, after have created viewb, assign viewb.viewa = self.viewa. , in viewb.m, not create new viewa, instead utilize property self.viewa, can alter viewa's background color. in viewb.m

[[self.viewa colorview] setbackgroundcolor:[uicolor greencolor]];

ios objective-c xcode subview

No comments:

Post a Comment