我正试图在一个视图上设置一个变量,而我正准备加载这个视图。下面是设置它的代码:
NSInteger amountOfQuestions = [self.questions.text intValue];
Timer_ViewController *tvc = [[Timer_ViewController alloc] initWithNibName:@"Timer_ViewController" bundle:nil];
tvc.amountOfQuestions = &amountOfQuestions;下面是Timer_ViewController的@接口:
@interface Timer_ViewController : UIViewController
{
NSInteger amountOfQuestions;
}
@property (nonatomic) NSInteger *amountOfQuestions;
@end我是objective-c的新手,因此指出明显的设计缺陷将不胜感激。
发布于 2012-09-14 08:08:59
你不应该让NSInteger成为一个指针--它不是一个对象类型,而仅仅是一个普通原始类型的typedef。如果您使用的是相对较新的Xcode版本,则可以使用下面这样的代码:
@interface Timer_ViewController : UIViewController
@property (nonatomic, assign) NSInteger amountOfQuestions;
@end并使用以下命令进行设置:
tvc.amountOfQuestions = [self.questions.text intValue];您甚至不必声明实例变量或@synthesize属性- Xcode将为您处理它。
https://stackoverflow.com/questions/12416446
复制相似问题