2013-07-14 18 views
0

這是我的代碼內EXC_BAD_ACCESS同時加入一個目的是一個陣列的開關

INT indiceCorrente = 0; int differenza = delegate.reader.feedItems.count;

while(variable!=0){ 
switch(variable){ 

case 1: ---- 
case 2: ---- 


default: { 

       NSMutableIndexSet *add=[[[NSMutableIndexSet alloc]init] autorelease]; 
       [add addIndex:indiceCorrente]; 
       [add addIndex:indiceCorrente+1]; 
       [add addIndex:indiceCorrente+2]; 
       [self aggiungiElementoArrayLettura:add]; 





       //[page addObject:@"makeLayout3"]; 
       NSMutableArray *pagina=[[NSMutableArray alloc]init]; 

       indiceCorrente=indiceCorrente+1; 
       [pagina addObject:indiceCorrente]; <------ EXC_BAD_ACCESS WHY???? 
       indiceCorrente=indiceCorrente+1; 
       [pagina addObject:indiceCorrente]; 
       indiceCorrente=indiceCorrente+1; 
       [pagina addObject:indiceCorrente]; 


       [pages addObject:pagina]; 

      } 
} 
} 
+0

是什麼aggiungiElementoArrayLettura – logixologist

+0

您需要的對象,而不是一個'int',這是一個基本類型。看到像這樣的問題:http://stackoverflow.com/questions/10486519/adding-integer-to-nsmutablearray –

回答

2

您不能將基本類型(int,float,double ...)添加到Foundation集合類中。您只能添加對象。當你嘗試添加一個int時,它被轉換成一個指針(id),並且數組試圖保留它。嘗試在NSNumber中包裝你的整數。這看起來就像

[pagina addObject:@(indiceCorrente)]; 

[pagina addObject:[NSNumber numberWithInt:indiceCorrente]]; 
相關問題