这里有严重的问题......如果我尝试 NSLog 我的自定义对象的实例变量,我会得到 ECX_BAD_ACCESS。在我的 ViewController 中调用以下函数,payload
保存从 url 中提取的字符串数据。
- (void) initVcardWithData:(NSString *)payload {
NSLog(@"1. initVcardWithData");
aVCard = [[vcardItem alloc] initWithPayload:payload];
VCardViewController *aVCardViewController = [[VCardViewController alloc] initWithVCard:aVCard];
[self presentModalViewController:aVCardViewController animated:YES];
[aVCard release];
}
到现在为止还挺好。initWithWithVCard 函数如下,theVCard
在theVCardN
@implementation 中定义,在(.h) 中也设置为@property (nonatomic, retain):
-(id)initWithVCard:(vcardItem *)aVCard {
if(self = [super init]) {
theVCard = [aVCard retain];
theVCardN = [theVCard.PersonName retain];
}
NSLog(@"---- vCardViewController :: initWithVcard :: FirstName: %@", theVCard.PersonName.FirstName);
return self;
}
如果我theVCardN
在我的 ViewControlleraVCardViewController
中访问对象,那么ViewDidLoad
一切都会像魅力一样。我用该对象的数据设置了一些标签。
如果然后我尝试theVCardN
从连接到 View 中的按钮的 IBAction 调用的函数中访问实例变量,我会在调试器控制台上收到 EXC_BAD_ACCESS 错误。尝试从实例变量中提取数据的函数如下:
-(IBAction)addressbookButtonTapped {
NSLog(@"RETAIN COUNT FOR theVCard: %i", [theVCard retainCount]);
NSLog(@"RETAIN COUNT FOR theVCardN: %i", [theVCardN retainCount]);
NSLog(@"Save to Adressbook: %@", theVCardN.FirstName);
//[self dismissModalViewControllerAnimated:YES];
}
调用 NSLog 之前的 RetainCountertheVCardN
输出“1”。然后 NSLog 行在调试器控制台中返回 EXC_BAD_ACCESS。
任何的想法 ?