我有一个我想存储字符串的类。这个类是一个控制器。现在我想从bController中存储一个字符串,并在cController中存储NSLog字符串。当我尝试这种情况时,cController中的日志输出始终为空。任何帮助将非常感激。跨类共享属性变量
aController.h:
@interface aController : NSObject
@property (nonatomic, retain) NSString * testingProperty;
aController.m:
#import "aController.h"
@implementation aController
@synthesize testingProperty = _testingProperty;
bController.m:
#import "bController.h"
#import "aController.h"
@implementation bController
-(void)didSomething
{
aController* aTest = [[aController alloc] init];
aTest.testingProperty = @"Test String";
}
cController.m
#import "cController.h"
#import "aController.h"
@implementation cController
-(void)didSomethingElse
{
aController* bTest = [[aController alloc] init];
NSLog(@"%@",bTest.testingProperty); //output is: (null)
}
意味着'bController didSomething'永远不会被调用。在那里放一个日志语句来验证它是否被调用 –