2012-05-18 23 views
0

我使用这个呼叫切换图像每4秒:目标C afterDelay

- (void) settheimage { 
    cur+=1; 
    waits=0; 
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(settheimage) object:nil]; 
    jpg = [NSString stringWithFormat:@"%@/%@_%d",current_anim,current_anim, cur]; 
    img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jpg ofType:@"jpg"]]; 
    [self performSelector:@selector(settheimage) withObject:nil afterDelay:4.0]; 
} 

它工作在第一图像上,但它崩溃之后。 我不想使用uiimage动画,因为我有很多图像,并且uiimage动画的加载需要很长时间。

回答

1

我猜你current_anim是由你的方法被调用时(自动)释放,导致一个悬挂指针和崩溃(EXC_BADACCESS,我想?)。您需要手动保留它,使其成为保留属性,或者开始使用ARC。

无论哪种情况,您应该关于内存管理read something