Questo pezzo di codice mi disturba, qualche idea del perché? allButtons
è un NSMutableArray
, contiene 3 oggetti, a=0, b=1
, a e b sono int
tipoCome scambiare valori in NSMutableArray?
if(a != -1 && b!= -1){
//Swap index in "allButtons"
id tempA = [allButtons objectAtIndex:a];
id tempB = [allButtons objectAtIndex:b];
[allButtons replaceObjectAtIndex:a withObject:tempB]; //Seg fault here?????
[allButtons replaceObjectAtIndex:b withObject:tempA];
needLoad = false;
[self setUpButtons];
}
EDIT:
NSMutableArray *allButtons = //fetch the array from Coredata. This work since I display the data onto the screen, plus, [allButtons count] return 3, and a=0, b=1
f(a != -1 && b!= -1){
//Swap index in "allButtons"
[allButtons exchangeObjectAtIndex:a withObjectAtIndex:b];
needLoad = false;
[self setUpButtons];
}
Può essere utile per inviare il messaggio di errore effettivo, se possibile. Sarebbe probabilmente anche utile pubblicare la dichiarazione della classe in modo che possiamo vedere se allButtons è una proprietà e, in tal caso, quali sono le semantiche di gestione della memoria, ecc. – jlehr