Objective-C Passing a variable to another IBAction

Posted by StuR on Stack Overflow See other posts from Stack Overflow or by StuR
Published on 2010-06-12T13:06:44Z Indexed on 2010/06/12 13:12 UTC
Read the original article Hit count: 234

Filed under:

This works fine:

NSString *myVariable;

- (IBAction) doFirstAction {
myVariable = @"123456789";
}

- (IBAction) doSecondAction {
NSLog(@"%@",myVariable);
}

However, if I do this (substituting the @"123456789" for some code which returns the same value ie "123456789") I cannot access the value in doSecondAction.

NSString *myVariable;

- (IBAction) doFirstAction {
myVariable = [imageNode getAttributeName:@"value"];
}

- (IBAction) doSecondAction {
NSLog(@"%@",myVariable);
}

Any clue as to why I cant access myVariable outside of doFirstAction?

© Stack Overflow or respective owner

Related posts about objective-c