简体   繁体   中英

Error: [__NSArrayM addObject:], NIL object

I receive the following error: [__NSArrayM addObject:] , NIL object. but not crash ,I want to know why display this remind. here is my code

NSMutableArray *picturesCounts = [NSMutableArray array];
NSMutableArray *bigUrlArray = [NSMutableArray array];
NSMutableArray *pitcturesArray = [NSMutableArray array];
NSInteger i = 1;
for (TNHotelPictures *picture in pictures) {
    NSString *pictureCounts = [NSString stringWithFormat:@"%ld",(long)picture.images.count];
    [picturesCounts addObject:pictureCounts];
    [pitcturesArray addObject:picture.images];

    for (TNHotelDetailPhotoImages *photoImage in picture.images) {
        [bigUrlArray addObject:photoImage.bigUrl];
    }
    i++;
}
NSInteger imageInAllIndex = imageIndex;
NSMutableArray *imagesCount = [NSMutableArray array];
for (NSInteger m = 0; m<i; m++) {
    imagesCount = pitcturesArray[(typeIndex-(m+1))] ;
    imageInAllIndex += imagesCount.count;
}

NSMutableArray *array = [NSMutableArray array];
    for (NSString *url in bigUrlArray)
    {
        if (![url isKindOfClass:[NSString class]])
        {
                return;
        }
    TNHotelPhoto *photo = [[TNHotelPhoto alloc] initWithImageURL:[NSURL URLWithString:url]];
        [array addObject:photo];
    }

TNHotelPhotoSource *source = [[TNHotelPhotoSource alloc] initWithPhotos:array];
TNHotelDetailPhotoBrowserViewController *browserVC = [[TNHotelDetailPhotoBrowserViewController alloc] initWithPhotoSource:source WithImageIndex:imageInAllIndex>=0?imageInAllIndex:0 andImageArray:pictures andTypeIndex:typeIndex];

[UIManager showViewController:browserVC];

}

It means that the object has been initialized and holding a reference in memory. Its not a NIL .

See your code:

for (TNHotelPictures *picture in pictures) {
    NSString *pictureCounts = [NSString stringWithFormat:@"%ld",(long)picture.images.count];
    [picturesCounts addObject:pictureCounts];
    [pitcturesArray addObject:picture.images];

    for (TNHotelDetailPhotoImages *photoImage in picture.images) {
        [bigUrlArray addObject:photoImage.bigUrl];
    }
    i++;
    }

I think you should check the picture whether its properties pictureCounts , images , bigUrl are not nil.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM