添加项目到NSMutableArray不起作用

时间:2012-11-29 01:17:39

标签: iphone ios nsmutablearray

我正在尝试创建一个数字数组,稍后我会用它来确定tableviewcells的大小。

但是我对数组有一些问题,在我的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 ++;
}

那么,如果我试图从我的数组中的每个对象获取值,那么if语句可以正常工作,但是当我尝试将它们添加到我的新数组时,它总是返回为NULL。 / p>

1 个答案:

答案 0 :(得分:1)

移动评论以回答

你需要像

这样的东西
heightArray = [NSMutableArray arrayWithCapacity:seriesSearchArray.count] 
相关问题