iphone - Access UIView with Class Method? -
i have 2 view controllers aviewcontroller , bviewcontroller example. want add ui element in second bviewcontroller first aviewcontroller. thought make happen through class method uiview not accessable in bviewcontroller's class method when called aviewcontroller.
implementation of bviewcontroller +(void)addthatbutton{ uibutton *btn = ...... [self.view addsubview:btn]; //<== error //[bviewcontroller.view addsubview:btn]; //<== error }
implemention of aviewcontroller [bviewcontroller addthatbutton];
error message "request member 'view' in not structure or union". how implememnt need in right way or, in other words, how access bviewcontroller view class?
thanks
you need create function in bviewcontroller
in bviewcontroller.h
uibutton *btnb; -(void)passbuttonfroma:(uibutton *)btn;
in bviewcontroller.m
-(void)passbuttonfroma:(uibutton *)btn{ btnb = btn; } -(void)viewwillappear:(bool)animated{ [self.view addsubview:btnb]; }
in aviewcontroller.m
bviewcontroller *bviewcontroller =[[bviewcontroller alloc]initwithnibname:.. ...]; //allocated bviewcontroller using nib file [bviewcontroller passbuttonfroma:btna]; [self.navigationviewcontroller pushviewcontroller:bviewcontroller animated:yes];
Comments
Post a Comment