ios - Updating UILabel in Child View 1 after Global Variable Update in Child View 2 -
i have made simple app test , cannot figure out. have ipad storyboard have put 2 container views shown below. have label in 1 view , button in another. button increment label, 1 number @ time.
my problem not passing value or incrementing, getting view load new value. each container has own viewcontroller
some code below, although sparse ive written bunch , deleted didn't work. please correct format. keep general format, updating global variable within button , updating label.
labelviewcontroller.h #import <uikit/uikit.h> @interface labelviewcontroller : uiviewcontroller @property (weak, nonatomic) iboutlet uilabel *checklabel; -(void)loadlabel; @end
labelviewcontroller.m #import "labelviewcontroller.h" #import "parentviewcontroller.h" @interface labelviewcontroller () @end @implementation labelviewcontroller @synthesize checklabel; -(void)loadlabel{ checklabel.text = [nsstring stringwithformat:@"%d",value]; [self.view setneedsdisplay]; } - (void)viewdidload { [self loadlabel]; [super viewdidload]; }
buttonviewcontroller.h #import <uikit/uikit.h> @interface buttonviewcontroller : uiviewcontroller - (ibaction)checkbutton:(id)sender; @end
buttonviewcontroller.m #import "buttonviewcontroller.h" #import "parentviewcontroller.h" #import "labelviewcontroller.h" @interface buttonviewcontroller () @end @implementation buttonviewcontroller - (ibaction)checkbutton:(id)sender { value++; nslog(@"%d",value); labelviewcontroller *fnc = [[labelviewcontroller alloc] init]; [fnc loadlabel]; } - (void)viewdidload { [super viewdidload]; }
picture at: http://farm4.staticflickr.com/3822/9469907420_746db25b23_b.jpg
in buttonviewcontroller, don't want alloc init'ing instance of labelviewcontroller -- 1 that's on screen exists. both child view controllers instantiated before parent controller is. so, need reference labelviewcontroller that's on screen. can self.parentviewcontroller.childviewcontrollers[0] (that 0 might have 1 -- don't know controller which).
labelviewcontroller *fnc = self.parentviewcontroller.childviewcontrollers[0]; [fnc loadlabel];
Comments
Post a Comment