2011-08-15 21 views
0

我有,我不能從我的課到其他的一個獲取數據的問題...initWithDictionary

要做到這一點,我創建了這個方法在課堂上,我初始化(angebotPage):

- (id) initWithDictionary:(NSDictionary *)dictionary 
{ 
self = [super init]; 

if (self) { 
    dict = [dictionary retain]; 
} 

    return self; 
} 

從其他類的調用看起來是這樣的:

angebotPage *page; 
angebotPDF = [[PDFDocument alloc] init]; 
page = [[angebotPage alloc] initWithDictionary:dictionary]; 

我得到的錯誤是EXC_BAD_ACCESS在我做這一行:

dict = [dictionary retain]; 

但是爲什麼?我需要保留它,因爲我將它用於下一個程序步驟..但沒有保留我不能使用它(EXC_BAD_ACCESS來自其他地方...)

+2

如何在下面的代碼中分配你的'字典'對象? '頁= [[angebotPage的alloc] initWithDictionary:辭典];' –

+0

字典只是填充有測試數據: 詞典= [NSDictionary的dictionaryWithObjectsAndKeys: @ 「/選擇/ picture.png」,@ 「盧卡」, @ 「/home/nico/birthday.png」,@「生日照片」, @「/ home/nico/birthday.png」,@「生日照片」, @「/ home/marghe/pic.jpg」,@ 「我的妹妹」,無]; 對不起。我是一個noob;)但我真的想賣掉這個問題! – chr1s9r

+1

你在哪裏做這個?請記住[NSDictionary dictionaryWithObjectsAndKeys:id ...,nil];返回一個自動發佈的NSDictionary給你。如果我是你,我會做這樣的事情:'NSDictionary * dictionary = [[NSDictionary alloc] initWithObjectAndKeys:id ...,nil];'然後在您將它提供給'page = [[ angebotPage alloc] initWithDictionary:dictionary];'。像這樣:'[字典發佈];' –

回答

0

我建議您使用dict屬性代替。

@property (retain) NSDictionary *dict; 

,然後分配與self.dict = dictionary.字典這是假設在字典中的所有對象被正確地保持在第一位置。如果有疑問,請嘗試使用空字典。

+1

這並不能解決字典在'initWithDictionary:'試圖保留它之前被過度釋放的問題。你仍然會試圖保留一個死對象。 –

相關問題