iphone - Pass Data to Subview -
how can pass data subview?
subviewviewcontroller.h:
@property (weak, nonatomic) iboutlet uilabel *lblname; tableviewcontroller.m:
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { // load subview subviewviewcontroller *svc = [self.storyboard instantiateviewcontrollerwithidentifier:@"subviewviewcontroller"]; svc.lblname.text = @"test"; // it's not working properly. svc.view.frame = cgrectmake(20, 60, svc.view.frame.size.width, svc.view.frame.size.height); [self addchildviewcontroller: svc]; [svc didmovetoparentviewcontroller:self]; [self.view addsubview:svc.view]; }
svc.lblname.text = @"test"; wont work label not yet initialised. reason being view having label not loaded memory until [self.view addsubview:svc.view]; , hence lblname nil... how fix that??
moving line svc.lblname.text = @"test";below [self.view addsubview:svc.view]; fix issue of property initialisation when scv.view added subview lblname assigned property/outlet..
hope work if else paired correctly in ur code.
Comments
Post a Comment