I'm trying to set a variable on a view that im getting ready to load. Heres the code for setting it:
NSInteger amountOfQuestions = [self.questions.text intValue];
Timer_ViewController *tvc = [[Timer_ViewController alloc] initWithNibName:@"Timer_ViewController" bundle:nil];
tvc.amountOfQuestions = &amountOfQuestions;
And here's the @interface for Timer_ViewController:
@interface Timer_ViewController : UIViewController
{
NSInteger amountOfQuestions;
}
@property (nonatomic) NSInteger *amountOfQuestions;
@end
Im relatively new to objective-c so pointing out of obvious design flaws would be appreciated.
You shouldn't make NSInteger a pointer - it's not an object type, just a typedef of a plain primitive type. If you're using a relatively recent version of Xcode, you can go with something like this:
@interface Timer_ViewController : UIViewController
@property (nonatomic, assign) NSInteger amountOfQuestions;
@end
And set it using:
tvc.amountOfQuestions = [self.questions.text intValue];
You don't even have to declare the instance variable or @synthesize the property - Xcode will handle it for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With