ios - Loading a nib file inside a UIViewController -
i'm experimenting on how load nib files uiviewcontroller
.
i have created separate nib file called email. first noticed when view controller loaded, initwithnibname
method isn't getting called. called viewdidload
method manually this,
[self initwithnibname:@"email" bundle:[nsbundle mainbundle]];
it did not work. got warning saying expression result unused.
and searched on internet , came across this article , implemented loadview
method described so,
- (void)loadview { [super loadview]; uinib *nib = [uinib nibwithnibname:@"email" bundle:nil]; [nib instantiatewithowner:self options:nil]; }
the method gets called still view controller empty!
can tell me i'm overlooking here , how can done?
thank you.
update:
first off, responses. voromax , svena's answers suggest should remove segues , load nibs automatically i'm not fond of. anil's answer works find , have 1 last hurdle jump.
i have multiple nib files. depending on user's selection, should load specific nib. tried was, put nibs inside array so,
- (void)loadview { [super loadview]; nsarray *nibs = [[nsarray alloc] initwithobjects: [[nsbundle mainbundle] loadnibnamed:@"facsimile" owner:self options:nil], [[nsbundle mainbundle] loadnibnamed:@"email" owner:self options:nil], [[nsbundle mainbundle] loadnibnamed:@"memorandum" owner:self options:nil], [[nsbundle mainbundle] loadnibnamed:@"projectmemo" owner:self options:nil], nil]; self.view = [nibs objectatindex:0]; }
and access using index self.view = [nibs objectatindex:1];
. throws error *terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nsarraym _setviewdelegate:]: unrecognized selector sent instance 0xd56fd20'*
why error coming up? if not possible, i'm open suggestions.
thanks again. , sorry kinda dragging out bit.
use below code load view nib , use view controller's view
- (void)loadview { [super loadview]; nsarray *nib =[[nsbundle mainbundle]loadnibnamed:@"test" owner:self options:nil]; self.view = [nib objectatindex:0]; }
edit
load single nib according user selection. see loading of single nib
nsarray *nib =[[nsbundle mainbundle]loadnibnamed:@"test" owner:self options:nil];
will returns array of objects. updated question can see storing these arrays array. nib array array of 'array' objects.
self.view = [[nibs objectatindex:0]objectatindex:0];
will work.
but not good, load single nib according user choise
Comments
Post a Comment