I do not understand how to declare an pointer that can be accessed in more than one method. The following code uses myContainer
to store a number which is utilized when useMyContainer
is called.
@interface MyViewController : UIViewController {
NSString *myContainer;
IBOutlet UILabel *display;
}
- (IBAction)storeToMyContainer: (UIButton *)sender;
- (IBAction)useMyContainer: (UIButton *)sender;
@end
@implementation MyViewController
- (IBAction)storeToMyContainer: (UIButton *)sender {
myContainer = sender.titleLabel.text;
}
- (IBAction)useMyContainer: (UIButton *)sender {
[someOtherClass doSomethingWith:[myContainer doubleValue]];
}
@end
What I don't understand is that when I use display
in the same manner, I don't have a problem. What do I need to do to access myContainer
in useMyContainer
in this manner?
Some thoughts: I know this is a memory management issue, and I am almost sure that a retain
is being called on display (probably by the .xib file?) and that is why display
hangs around long enough to be used in both methods.
I know a work around that involves using a double and an int, but I consider this to be messy, and as I'm taking a class on this I wanna to know the baller way to handle this.
Thanks for your help!