0

我试图在我将单元格文本变灰之前查看我的 nsarray 是否有数据 - 但由于某种原因,如果使用可怕的 SIGBRT 进行 if 评估,它会爆炸......如果密钥“myIndex”存在,则以下代码可以正常工作...... .当用户在应用程序结束时发送他的订单时,我删除了密钥....所以当应用程序在订单后打开时我想跳过?????

if(![[[inList objectAtIndex:0] objectForKey:@"myIndex"] count] == 0){

       NSArray *myIndexList = [[inList objectAtIndex:0] objectForKey:@"myIndex"];
       NSLog( @"data from INDEX !!!!!!!! %@", myIndexList);

       for(int n=0; n<[myIndexList count]; n++)
       {
           if(indexPath.row == [[myIndexList objectAtIndex:n] integerValue])
           {
               cell.textLabel.textColor = [UIColor lightGrayColor];
           }
       }

   }

非常感谢您的时间和帮助。

4

3 回答 3

0

您可以像这样检查对象是否存在:

if([[inList objectAtIndex:0] objectForKey:@"myIndex")
{
    //It exists, do something (otherwise ignore it)
}
于 2012-05-30T01:14:11.067 回答
0

您需要首先确保 inList 中有一个对象:

if ([inList count] > 0) {
    if([[[inList objectAtIndex:0] objectForKey:@"myIndex"] count] > 0) {
        // there is a valid object
    }
}
于 2012-05-30T01:21:26.690 回答
0

检查 NSArray 是否有特定对象的数据:

if ([[NSString stringWithFormat:@"%@", [inList objectAtIndex:0]] length] == 0) {
    //Do somthing if the NSArray object is empty.
} else {
    //Do somthing if the NSArray object countains somthing.
}

检查 NSArray 中的任何对象是否有数据:

for (int count = 0; count < inList.count; count++) {
    if ([[NSString stringWithFormat:@"%@", [inList objectAtIndex:count]] length] == 0) {
        //Do somthing if the NSArray object is empty.
    } else {
        //Do somthing if the NSArray object countains somthing.
    }
}
于 2012-05-30T01:24:46.110 回答