Este pedazo de código me falla, ¿por qué? allButtons
es una NSMutableArray
, que contiene 3 objetos, a=0, b=1
, ayb son int
tipoCómo intercambiar valores en 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];
}
Puede ser útil para enviar el mensaje de error real, si es posible. Probablemente también sea útil publicar la declaración de clase para que podamos ver si allButtons es una propiedad, y si es así, cuál es su semántica de gestión de memoria, etc. – jlehr