iOS: changing a UILabel text of a modal view programmatically -


i have app has 2 screens. in first screen there's button opens second screen modal view via modal segue, , has uilabel.

i want uilabel have text varies depending on how many times user clicks button (they're hints: user can click button , see hint 3 times). i'm doing following method every time click button:

- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     if ([segue.identifier isequaltostring:@"tipmodal"]) {         quiztipviewcontroller * detailviewcontroller = (quiztipviewcontroller *) segue.destinationviewcontroller;         detailviewcontroller.delegate = self;         detailviewcontroller.tiptext = self.quiz.currenttip;         [detailviewcontroller.numbertipstext settext:[nsstring stringwithformat:@"pistas para la respuesta (usadas %ld de 3)", (long)self.quiz.tipcount]] ;         nslog(@"%d", self.quiz.tipcount);         nslog(@"%@", detailviewcontroller.numbertipstext.text);     } } 

the last 2 logs have following output:

2013-05-14 19:10:47.987 quotequiz[1241:c07] 0 2013-05-14 19:10:47.989 quotequiz[1241:c07] hints (0 out of 3 used) 

nevertheless, text in uilabel empty.

in .h file of view controller of modal window, define uilabel as:

@property (strong, nonatomic) iboutlet uilabel* numbertipstext; 

and created in implementation file:

-(uilabel *)numbertipstext {     if (!_numbertipstext) {         _numbertipstext = [[uilabel alloc] init];     }     return _numbertipstext; } 

any idea why happening, please?

thanks lot in advance!

the reason label has no text because assign text label created in your

-(uilabel *)numbertipstext 

getter. then, when controller's view loaded nib, numbertipstext property overwritten label loaded nib, not contain text. solution remove getter creates new uilabel , then:

- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     if ([segue.identifier isequaltostring:@"tipmodal"]) {         quiztipviewcontroller * detailviewcontroller = (quiztipviewcontroller *) segue.destinationviewcontroller;         detailviewcontroller.delegate = self;         detailviewcontroller.tiptext = self.quiz.currenttip;         //numberoftipstext nsstring property         detailviewcontroller.numberoftipstext = [nsstring stringwithformat:@"pistas para la respuesta (usadas %ld de 3)", (long)self.quiz.tipcount];     } } 

in viewdidload method of quiztipviewcontroller:

- (void) viewdidload {     [super viewdidload];     self.numberoftipslabel.text = self.numberoftipstext; } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -