ios - 模拟器崩溃 "[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'”

标签 ios nsmutablearray

我正在开发一个将使用自定义图像选择器的应用程序,尽我所能尝试,我似乎无法让该应用程序正常运行。 Xcode 调试器标记以下“线程 1:程序收到信号:“SIGABRT”。”

  - (id) init { 
    if ((self = [super init])) {
        _images =  [[NSMutableArray alloc] init];
        _thumbs =  [[NSMutableArray alloc] init];
    }
    return self;
}

- (void)addImage:(UIImage *)image {
    [_images addObject:image];
    [_thumbs addObject:[image imageByScalingAndCroppingForSize:CGSizeMake(64, 64)]];
}

这是在新调试器上的 xcode 4 中。 提前致谢。

最佳答案

其中一个对象是 nil。以下代码将帮助您发现是哪一个:

- (void)addImage:(UIImage *)image 
{
    if (image)
    {
        [_images addObject:image];
    }
    else
    {
        NSLog(@"image is nil");
    }

    UIImage *newImage = [image imageByScalingAndCroppingForSize:CGSizeMake(64, 64)];
    if (newImage)
    {
        [_thumbs addObject:newImage];
    }
    else
    {
        NSLog(@"newImage is nil");
    }
}

关于ios - 模拟器崩溃 "[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5852387/

相关文章:

ios - UIView.animateWithDuration 的交互式过渡完成 block 从未在 animateTransition 内部调用

ios - UIBarButtonItem 将图标填充更改为白色 ios

cocoa - 为什么我的代码输出*nil description*

objective-c - 绘制矩形看到空数组

objective-c - 如何通过类别扩展向 NSMutableArray 添加属性?

objective-c - 智能识别电话号码和文本(包括国际号码)

ios - 更改UIDocumentInteractionController上的NavigationBar背景

iphone - iOS,使用下划线与直接使用 iVar

ios - 如何处理 Swift 中的竞争条件读/写问题?

cocoa-touch - cocoa NSString 爆炸