Get~Set value from different ViewControllers XCode
I have a two ViewControllers
- Level4ViewContr开发者_StackOverflow社区oller
- Level5ViewController
In Level4ViewController
I have a NSNumber *averagePred;
I would like to get and set the value of averagePred
from Level5ViewController
.
I have already entered the @property (nonatomic, retain)
... for each.
How can I manage this, I've tried just putting the properties in my AppDelegate and using:
appDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])
This didn't seem to work, and I would like to be able to get this sorted.
And a final part, if anyone can help me on:
I have:
NSNumber *averagePred;
In my header file
In the methods I have a float average;
and using averagePred = [NSNumber numberWithFloat:average];
didn't work. Can anyone help me out here. Thanks
Level5VC needs a reference to Level4VC, so it can do this:
myLevel4VC.averagePred = 159.3;
You can give level5 the reference by passing it into a custom constructor, or by having a level4VC ivar in level5 that is set by whoever invokes level5.
精彩评论