这就是我的实体类的外观:
BaseDataEntity.h
#import -Foundation/Foundation.h
@interface BaseDataEntity : NSObject
@property (assign) NSMutableArray *cbxDataList;
@property (assign) NSString *resaultText;
@end
基本数据实体.m
#import "BaseDataEntity.h"
@implementation BaseDataEntity
@synthesize cbxDataList = _cbxDataList;
@synthesize resaultText = _resaultText;
@end
这就是我尝试访问它们的方式:
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification{
BaseDataEntity *aBaseDataEntity = [[BaseDataEntity alloc] init];
[self setBaseDataEntity:aBaseDataEntity];
}
-(IBAction)ReadPort:(id)sender {
NSMutableArray* array = [[NSMutableArray alloc] init];
for (int i=0; i<10; i++) {
NSString *temp = [NSString stringWithFormat:@"Test %d", i];
[array addObject:temp];
}
[self.baseDataEntity setCbxDataList:array];
NSLog(@" cbxDataList count = %lu",[array count]);
[array release];
[self.baseDataEntity setResaultText:@"Test"];
[self updateUserInterface:TRUE];
}
-(void)updateUserInterface:(BOOL)piClear{
NSString *textValue = [NSString stringWithFormat:@"%@"
,[self.baseDataEntity resaultText]];
if([self.ResaultTextField stringValue] != nil && !piClear){
textValue = [NSString stringWithFormat:@"%@\n%@", textValue
,[self.ResaultTextField stringValue]];
}
NSMutableArray* array = [[NSMutableArray alloc] initWithArray:
[self.baseDataEntity.cbxDataList value]];
for (int i = 0; i < [array count]; i++) {
textValue = [NSString stringWithFormat:@"%@\n%@", textValue
,[array objectAtIndex:i]];
}
[array release];
[self.ResaultTextField setStringValue:textValue];
}
问题是我可以更新resaultText
并访问它的价值。但是cbxDataList
值总是空的。