2012-05-18 57 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