ios - Loading custom cell from nib does not finish on time -
i have uiview contains 2 uitableviews, toggled between using segmented control in navigation bar of uiview.
the first table (ingredients) uses standard cells, , working fine.
the second table (recipes) uses custom cell loaded nib. problem when app launched , recipes table last visible (from state preservation), when view appears cells presented using standard cells. if user cycles mentioned segmented control, appear intended upon return recipes table.
the relevant parts of tableview:cellforrowatindexpath:
in viewcontroller:
// check displaying right table if (tableview == self.recipestable) { static nsstring *recipecellidentifier = @"recipecellidentifier"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:recipecellidentifier]; nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"recipecell" owner:self options:nil]; if(nib.count > 0) { cell = self.customcell; } else { nslog(@"failed load customcell nib file!"); } } // set number of properties of custom cell // ... return cell;
self.customcell
iboutlet uitableviewcell bound cell in actual nib file using file's owner (the nib contains uitableviewcell).
to me, indicates nib not load in time, i.e not until after view has first appeared.
i have tried moving nib loading viewdidload
method, forcing reloaddata
, setneedsdisplay
@ end of viewwillappear:
no avail.
what puzzles me fact works long table custom cells not visible, switched after launch.
are subclassing uitableviewcell along nib file?
cause try use: (with recipecell name of subclass)
recipecell *cell = (recipecell *)[tableview dequeuereusablecellwithidentifier:recipecellidentifier]; if ( !cell ) { nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"recipecell" owner:self options:nil]; if(nib.count > 0) { self.customcell = [nib lastobject]; //assuming have 1 top level object //in nib cell = self.customcell; } else { nslog(@"failed load customcell nib file!"); } }
why use "customcell" property actually? assign , rid of self.customcell
cell = [nib lastobject];
Comments
Post a Comment