我想創建一個數組數組,我將稍後使用它來確定我的tableviewcells的大小。添加項目到NSMutableArray不起作用
但是我有一些與數組有關的問題後,我的while語句它回來爲NULL,但是當我記錄我從我的對象數組得到的值,他們是正確的...和if語句工作完美。
這是我的代碼,如果
int count = 0;
// Cell heights
int smallCell = 69;
int largeCell = 120;
NSNumber *currentHeight = [[NSNumber alloc] init]; // allows int to be stored into NSArray
while (count < seriesSearchArray.count) {
myObj = (SeriesSearchResultItem*)[dataArrayOfObjects objectAtIndex:count];
if (![myObj.seriesNote isEqualToString:@""]) {
NSLog(@"%@", myObj.seriesNote);
currentHeight = [NSNumber numberWithInt:largeCell];
NSLog(@"%@", currentHeight); // correct value shown
[heightArray addObject:currentHeight];
}
else {
currentHeight = [NSNumber numberWithInt:smallCell];
NSLog(@"%@", currentHeight); // correct value shown
[heightArray addObject:currentHeight];
}
NSLog(@"%@", heightArray); // NULL Shown
count ++;
}
因此多數民衆贊成,我想每個在我的陣列,其工作原理,對象獲得的價值,如果statment完美的作品,但後來當我嘗試添加他們到我的新數組它總是返回爲NULL。
您可能需要表現出更多的代碼。我沒有看到你創建(alloc/init)的heightArray。然後再次,這可能是問題... – DrC
我有@屬性/ @綜合heightArray,因爲我需要從其他方法訪問它後,我把它的值。 – HurkNburkS
創建指向它的指針。它實際上並不創建NSMutableArray。你需要像heightArray = [NSMutableArray arrayWithCapacity:seriesSearchArray.count] – DrC