在iphone中的警报视图

Ran*_*wan 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 ];
    }
Run Code Online (Sandbox Code Playgroud)

这显示错误---- alertView未声明和预期; 之前:

请帮我解决我的问题.当我点击警报按钮时,我想执行一些操作.

tas*_*oor 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];