2011-02-13 116 views
0

有人看到有什麼問題嗎?我有一個UIAltertView但是當我點擊任何兩個按鈕得到一個EXC_BAD_ACCESS:無法讓UIAlert工作

UIAlertView *alert = [[UIAlertView alloc] init]; 
    [alert setTitle:@"First Sync"]; 
    [alert setMessage:@"The App is going to do its first synchronisation. This might take a few moment..."]; 
    [alert setDelegate:self]; 
    [alert addButtonWithTitle:@"OK"]; 
    [alert addButtonWithTitle:@"Cancel"]; 
    [alert show]; 
    [alert release]; 

,並搭上了迴應:

#pragma mark UIAlertView 
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if (buttonIndex != 0) 
    { 
      NSLog(@"TEST1"); 
     return; 
    } 
NSLog(@"TEST2"); 
} 

它必須是簡單的東西...

+0

當您顯示警報時會發生什麼?警報的代表是否有可能被釋放? (嘗試使用NSZombiesEnabled運行) – Vladimir 2011-02-13 18:03:17

回答

0

如上所示,問題在於UIAlert是在一個線程中生成的。通過使用NSCondition並將Alert發送到後臺線程,我得到了工作線程在後臺線程等待用戶響應時等待。一旦響應到來,它表示工作線程繼續進行(因爲所需的數據在該點存儲在數據庫中)。

1

你「將不得不使用指定的初始化:

initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles: