严重问题在这里...我收到ECX_BAD_ACCESS如果我尝试NSLog我的自定义对象的实例变量。以下功能在我的ViewController中调用,保存从一个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定义且还设置为@property(非原子,保留)在(.H)。:
-(id)initWithVCard:(vcardItem *)aVCard {
if(self = [super init]) {
theVCard = [aVCard retain];
theVCardN = [theVCard.PersonName retain];
}
NSLog(@"---- vCardViewController :: initWithVcard :: FirstName: %@", theVCard.PersonName.FirstName);
return self;
}
如果我在的ViewController访问theVCardN
对象aVCardViewController
以内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];
}
的RetainCounter为theVCardN
右调用的NSLog输出“1”之前。 NSLog Line然后在Debugger Console中返回EXC_BAD_ACCESS。
有什么想法?
我的猜测是vCard设置不正确。在NSLog执行之前 – Eiko 2010-12-23 12:22:19
在gdb中打印值。你会知道什么是实际问题。在调试模式下,将光标放在该行上。左键单击出现的黄色标签并单击打印说明。你可以看到什么是价值。 – Raxit 2010-12-23 12:33:23
输出结果是:`打印VCardN.FirstName的描述:`没有更多 – MadMaxAPP 2010-12-23 14:11:49