ios - Changing a label in another view -
i have program multiple views, 1 of them has labels (labelview question), other has text fields(textview question). take info text fields, , put on label, think easiest way calling method labelview textview.
i have tried couple things:
i tried putting method in labelview changed label's values parameters. calling method in textview , passing data through parameters.
i tried making delegate, using this question. unfortunately last step (add
settingview.viewcontrollerdelegate=self
viewdidload
method) failed.settingview
undeclared identifier.
does know should do?
edit: here have done, using xman's parent/child view idea. in textview.m:
nsinteger curscore = [self.top1score.text integervalue]; nsinteger curphase = [self.top1phase.text integervalue]; self.top1score.text = [nsstring stringwithformat:@"%d", (curscore += [self.player1txt.text integervalue])]; if ([self.player1txt.text integervalue] < 50) { self.top1phase.text = [nsstring stringwithformat:@"%d", (curphase += 1)]; }
two ways achieve this.
1) make childview
childview of parentview
can directly access parentview
properties in childview
following
parentview.h
@interface parentview : uiview @property (nonatomic,strong) uitextfield *mytextfield; @end
childview.h
#import "parentview.h" @interface childview : parentview @property (nonatomic,strong) uilabel *mylabel; @end
2) use notification
put in firstview
textfield
:
[[nsnotificationcenter defaultcenter] postnotificationname:@"senddata" object:yourtextfiels userinfo:nil];
put in secondview
label
is.
[[nsnotificationcenter defaultcenter]addobserver:self selector:@selector(changelabelvalue:) name:@"senddata" object:nil];
and method
-(void)changelabelvalue(nsnotification *)irecognizer { uitextfield *mytextfield = irecognizer object]; //here can change value of label }
hope you.
Comments
Post a Comment