कोड खंड का यह टुकड़ा मुझ पर गलती है, कोई विचार क्यों? allButtons
एक NSMutableArray
है, यह 3 वस्तुओं, शामिल a=0, b=1
, ए और बी int
प्रकार के होते हैंएनएसएमयूटेबलएरे में मूल्यों को कैसे स्वैप करें?
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];
}
संपादित करें:
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];
}
यह यदि संभव हो तो वास्तविक त्रुटि संदेश पोस्ट करने के लिए, सहायक हो सकता है पारित करना होगा। यह कक्षा घोषणा को पोस्ट करने में भी मददगार होगा ताकि हम देख सकें कि सभीबटन एक संपत्ति है, और यदि हां, तो इसका मेमोरी प्रबंधन अर्थशास्त्र क्या है, आदि – jlehr