ios - UILabel is always nil -


i have following problem.

this code:

gtsearchviewcontroller* vc = [[gtsearchviewcontroller alloc] initwithnibname:@"gtsearchviewcontroller"                                                                           bundle:nil];  vc.headlinelabel.text = [[self.categoriearray objectatindex:indexpath.row] valueforkey:@"categoryname"];  [appdelegate().centerviewcontroller pushviewcontroller:vc                                               animated:yes]; 

as can see, try push new viewcontroller xib file , want set string in headlinelabel array self.categoriearray. when searchcontroller gets pushed, works perfect, headlinelabel nil.

i don't understand why, thought don´t need call "alloc-init" in searchcontroller because build interface builder?

your problem changing ui before loaded.

you should set label's text in viewdidload of view controller (it called after view loaded).


make nsstring property in searchviewcontroller class , set right after initialization.

vc.headlinetext = [[self.categoriearray objectatindex:indexpath.row] valueforkey:@"categoryname"]; 

then in searchviewcontroller should override viewdidload method:

 - (void) viewdidload{        [super viewdidload];        self.headlinelabel.text = self.headlinetext;     } 

p.s. of course assume you've set headlinelabel outlet correctly (from interface builder).


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -