2010-05-12 88 views
2

我真的被這一個puzzeled。我在我的應用程序中設置了兩個UIActionSheets。它們工作得很好,直到使用UIActionSheets中的取消按鈕。UIActionSheet取消按鈕不斷崩潰我的應用程序

當我離開頁面UIAactionSheet返回時,它崩潰了我的應用程序。

有沒有人有任何想法?

-(IBAction) phoneButtonClicked:(id)sender 
{ 
// open a dialog with just an OK button 
phoneActionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                delegate:self cancelButtonTitle:@"Cancel" 
                destructiveButtonTitle:nil 
                otherButtonTitles:[NSString stringWithFormat:@"Phone: %@",phone],nil]; 
phoneActionSheet.actionSheetStyle = UIActionSheetStyleDefault; 
[phoneActionSheet showInView:self.view]; // show from our table view (pops up in the middle of the table) 
[phoneActionSheet release]; 
} 

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 

if (actionSheet == phoneActionSheet) { 

    if(buttonIndex == 0){ 
      NSString *callPhone = [NSString stringWithFormat:@"tel:%@",phone]; 
      NSLog(@"Calling: %@", callPhone); 
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]]; 
    } 
} 

} 
+0

當應用程序崩潰時,是否有任何東西會記錄到控制檯?如果是這樣,發佈消息將有所幫助。 – jlehr 2010-05-12 14:42:23

回答

1

我會建議不釋放phoneButtonClicked中的phoneActionSheet。我懷疑你可能會試圖用一個糟糕的指針來做些事情。另一個很好的幫助是使用NSZombieEnabled

+0

控制檯中沒有記錄任何內容,但刪除了釋放命令。 – user337174 2010-05-12 14:53:40

+0

如果沒有該版本,工作表可能會泄漏。每次您調用phoneButtonClicked時,都會創建一個不再發布的新工作表。但是,您需要在表單被解散後釋放它,而不是在創建後纔會釋放它。 – JeremyP 2010-05-12 15:20:11

+0

我通常會在clickedButton和/或取消的調用中釋放動作表。這不是最好的,但它保持了他們的一生。 – 2010-05-12 15:43:38