Iphone 如何将UIImage添加到Objective-C中的MSMutableArray?

Iphone 如何将UIImage添加到Objective-C中的MSMutableArray?,iphone,objective-c,ios5,Iphone,Objective C,Ios5,我没有客观的c问题。如何将UIImage添加到MSMutableArray?以下是我的代码: MSMutableArray *arr = [[NSMutableArray alloc] init]; UIImage *image; UIGraphicsBeginImageContext(contextSize); { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextTranslateCTM(contex

我没有客观的c问题。如何将UIImage添加到MSMutableArray?以下是我的代码:

MSMutableArray *arr = [[NSMutableArray alloc] init];
UIImage *image;
UIGraphicsBeginImageContext(contextSize);
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(context, 0, pushUpSize);

    [screenWindow.layer renderInContext: context];  
    image = UIGraphicsGetImageFromCurrentImageContext();
}
UIGraphicsEndImageContext();
[arr addObject:image];
但当程序试图添加图像时,它会崩溃。我在某处读到它添加了一个变量而不是指针,对吗?如何将UIImage添加到数组中,它是一个对象,不是吗

谢谢

您正在初始化数组
arr
,但将图像添加到(显然是单元化的)数组
imageArr


根据您更新的代码,我想说
图像
对象可能是
nil
。使用
nil
值调用
addObject:
在thiesdiggity中是特别禁止的。

@thiesdiggity:从我所看到的代码中没有多少错误。但请尝试下面的代码,因为我认为
图像
对象是
nil

MSMutableArray *arr = [[NSMutableArray alloc] init];
UIImage *image;
UIGraphicsBeginImageContext(contextSize);
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(context, 0, pushUpSize);

    [screenWindow.layer renderInContext: context];  
    image = UIGraphicsGetImageFromCurrentImageContext();
}
UIGraphicsEndImageContext();

if(image != nil)
{
    [arr addObject:image];
}
如果您需要更多帮助,请告诉我,并发布您的崩溃日志以获得更多帮助


希望这有帮助。

当它崩溃时,日志中会显示什么?请张贴,以便我们可以帮助你更多的信息this@thiesdiggity:很高兴!我可以帮你。:)