如何检查alertview值

时间:2011-03-25 07:08:45

标签: iphone

这是我的代码:

self.myAlert = [[[UIAlertView alloc] initWithTitle:@"MNB" message:@"R u want to delete" delegate:self cancelButtonTitle:@"OK",nil otherButtonTitles:@"Cancel",nil] autorelease];
    [myAlert show];

在这里我想处理如果确定按钮单击并且也取消按钮,我想重定向页面如果单击确定按钮....我需要编码,IF条件语句时单击确定按钮.... .pls帮帮我....

3 个答案:

答案 0 :(得分:1)

阅读UIAlertViewDelegate协议参考。

您可以实施以下方法。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

答案 1 :(得分:1)

只需要像这样编写 UIAlertView的委托方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if(buttonIndex==1){
              NSLog(@"Cancelled Clicked");  
         } 
    if(buttonIndex==0){
          NSLog(@"O.K Clicked");  
         }
}

一定会工作:)

答案 2 :(得分:0)

您可以使用UIAlertView委托方法。例如

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
{
      if(buttonIndex == 0) //your OK button
      {
        //Some code here
      }
    else if(buttonIndex == 1)
      {
        //Some other code
      }
}
相关问题