2012-04-04 2 views
1

나는 objective-c 문제가있다. MSMutableArray에 UIImage를 어떻게 추가합니까? 다음은 가지고있는 코드입니다.Objective-C에서 MSMutableArray에 UIImage를 어떻게 추가합니까?

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를 배열에 추가하려면 어떻게해야합니까?

감사합니다.

+1

충돌이 발생했을 때 로그에 표시되는 내용은 무엇입니까? 우리가 이것을 더 잘 도울 수 있도록 게시 해주십시오. –

답변

0

@thiesdiggity : 내가 볼 수있는 것에서 코드에 별다른 차이가 없습니다.

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]; 
} 

이 더 많은 도움이 필요하면 알려줘 많은 도움이 도움이

희망을하여 충돌 로그를 게시하시기 바랍니다 :하지만 그냥이 image 객체가 nil 생각으로 아래 코드를보십시오.

+0

@thiesdiggity : 다행! 내가 너를 도울 수있어. :) –

0

배열 arr을 초기화하지만 이미지를 (분명히 단위화된) 배열 imageArr에 추가합니다.

업데이트 된 코드에 따르면 image 개체는 아마도 nil입니다. addObject:nil 값으로 사용하는 것은 docs에서 특별히 금지됩니다.

+0

미안하지만 오타였습니다. 코드를 업데이트했습니다. – thiesdiggity

관련 문제