2010-08-10 64 views
0

我遇到警報問題。當我將以下內容添加到我的程序時,它顯示錯誤:iPhone中的警報視圖

UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"That's it" message:@"THANKS FOR USING" delegate:self cancelButtonTitle:@"bye" otherButtonTitles:nil]; 

[alert show]; 

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
    { 
     NSLog(@"Button %d pressed", buttonIndex); 
     [ alertView release ]; 
    } 

這顯示錯誤---- alertView未聲明和預期;之前:

請幫我解決我的問題。當我點擊警報上的按鈕時,我想執行一些操作。

回答

5

您會在哪一行發生錯誤,確切的錯誤是什麼?你在接口聲明中添加了UIAlertViewDelegate協議嗎?看來你沒有。

而且您不需要在委託方法中釋放alertView。顯示後你可以放開它。

 
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"That's it" message:@"THANKS FOR USING" delegate:self cancelButtonTitle:@"bye" otherButtonTitles:nil]; 
[alert show]; 
[alert release];