objective c - IBAction Subview with Storyboard -


i'm trying add subview using storyboard. it's being displayed correctly, there's no button (ibaction) in subview works correctly, empty code, app crashes when clicked.

tableviewcontroller.m

... - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     // load subview         subviewviewcontroller *subview = [self.storyboard instantiateviewcontrollerwithidentifier:@"subviewviewcontroller"];     [self.view addsubview:subview.view]; } ... 

subviewviewcontroller.m

- (ibaction)btnclosesubview:(id)sender {     // crashes app when clicked, empty it's.  } 

you shouldn't add view controller's view view that, can trouble. when i've tried that, works , not. proper way add controller child view controller of tableviewcontroller:

subviewviewcontroller *subview = [self.storyboard instantiateviewcontrollerwithidentifier:@"subviewviewcontroller"]; [self addchildviewcontroller: subview]; [subview didmovetoparentviewcontroller:self]; [self.view addsubview:subview.view]; 

you need set frame of subview's view (subview.view.frame = self.view.bounds if want same size).

as alternative, create view, not view controller, in xib file, , add subview of view. in case, set file's owner of xib tableviewcontroller, , put button's method in tableviewcontroller.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -