-1

我将一个值存储在NSMutableArray...但是当我尝试检索它时,它找不到它。

我的目标是寻找信标主要 id。如果找到新的信标主要 id,我将其保存在数组中。所以下次当我读取信标主要 id 时,如果它已经存在于数组中,我不会使用它。

for (int i=0; i<numberOfBeacondsInRange; i++) 
{

    NSLog(@"Processing current beacon: %d of %d", i, numberOfBeacondsInRange-1);

    ESTBeacon *currentBeacon = [self.beaconsArray objectAtIndex:i];
    // not able to retrive values from the array to compare

    BOOL isPresent=NO;

    for (int j=0; j<100; j++)
    {
        if ([visitedBeaconsArrayMajor objectAtIndex:j] == currentBeacon.major)
        {
               NSLog(@"Already seen");
               isPresent=YES;
        }
     }

     if (isPresent==NO) 
     {
        [visitedBeaconsArrayMajor addObject:currentBeacon.major];
        NSLog(@"Add major:%@",currentBeacon.major);
     }
}
4

1 回答 1

3

通常情况下,如果您没有在NSMutableArray属性投入使用之前对其进行初始化,就会发生这种情况,visitedBeaconsArrayMajor = [[NSMutableArray alloc] init];导致它成为nil.

于 2014-05-23T04:08:38.370 回答