我有一個我想存儲字符串的類。這個類是一個控制器。現在我想從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'永遠不會被調用。在那裏放一個日誌語句來驗證它是否被調用 –