嚴重問題在這裏...我收到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