ios - Using multiple nib files with a single view controller? -
ios - Using multiple nib files with a single view controller? -
background
i'm using interface builder create ui app i'm working on. app has single screen displays series of buttons. clicking on button displays associated view overlays buttons. clicking button hides previous overlay view , displays one.
too create managing ui easier in ib i've decided create multiple nib files each sub view appear when clicking relevant button. i'm loading sub view's nib file in view controller's viewdidload
method using uinib
class.
the thought behind avoid having multiple views stacked on top of each other in single nib file hard manipulate in ib. have created views in code require lot of tedious coding layouts of each sub view quite complex (with multiple kid views).
example code loading sub view nib file.
- (void)viewdidload { uinib *asubviewnib = [uinib nibwithnibname:@"asubview" bundle:nil]; nsarray *bundleobjects = [asubviewnib instantiatewithowner:self options:nil]; // root view bundle array uiview *asubview = [bundleobjects objectatindex:0]; [self.view addsubview:asubview]; ...
the code above repeated other views.
to summarise have single screen iphone app has layered views shown/hidden clicking buttons. achieved single view controller associated nib file , series of additional nib files sub views loaded in view controller's viewdidload method.
questions!
sorry long introduction wanted clear doing.
is approach bad or unusual? are there potential issues doing way? what have other people done when need dynamic interface , still want maintain in interface builder?notes
before asks why don't display sub views on new screen , utilize navigation bar, allow me have reasons , understand ios ui guidelines. above utilize case not utilize case it's 1 describes problem without getting bogged downwards in development app.
also know have written sub views code each sub view has complex layout of kid views , lot of code , messing around seek , them looking right.
thanks in advance.
there isn't 1-to-1 relationship between view controllers , views. views contain many subviews, views themselves, literally doesn't create sense.
however, depending on complexity of views (including content), may want separate view controllers... or not.
for example, if have 2 sbuviews each tableviews, may want have 1 view controller each tableview. because each tableview looking @ same delegate methods, , if in same viewcontroller, delegate methods have differentiate between tableviews. delegate methods have signatures allow this, but, in experience, can create messy code design hard follow , hard manage.
on other hand, may have 2 tables managed same viewcontroller, 1 table filled meaningful info , other place holder (as when info source empty). 1 might visible while other not. why create life complicated creating 2 view controllers when both driven same info source (the model)?
in mind, comes downwards how hard follow , manage code. if complexity of using single view controller becomes burdensome, consider using more view controllers.
update
by way, have illustration working may illustrate similar situation. in inappsettingskit, lot of developers use, there several xib files pieces of main view. you can @ construction here on github. there 1 main view controllers , several xib files. (there phone call "helper" view controller , email composer view controller.) in example, xib files may used multiple times specify layout of table view cells. there no view controller each xib file, though. (the documentation inappsettingskit sparse, these things may not obvious taking quick @ it.)
ios ios4 uiview interface-builder nib
Comments
Post a Comment