我需要帮助才能将变量从一个类读取到另一个类。我已经关注了一些关于此的答案,但没有成功。
PP.h:
@interface PP : UIViewController
{
@public int fNum;
}
@property (readwrite, nonatomic) int fNum;
- (IBAction)setSomeNum;
@end
米:
@synthesize fNum;
- (IBAction)setSomeNum
{
fNum = 69;
NSLog(@"Set Num Activated %d",fNum); //OK
}
TryView.m:
#import "TryView.h"
#import "PP.h"
@interface TryView ()
@end
@implementation TryView
- (void)viewDidLoad
{
[super viewDidLoad];
PP *obj ;
int x = obj.fNum;
NSLog(@"Happines %d",x); //Prints 0
}
@end
怎么了,为什么打印 0?