【问题标题】:about UIAlert jumps to one xib关于 UIAlert 跳转到一个 xib
【发布时间】:2026-01-29 10:15:01
【问题描述】:

我有大约三个 xib 文件,a b c b上有一个按钮,点击它会显示警报,代码是

UIAlertView *alert = [[UIAlertView alloc] 
 initWithTitle:@"Warning"
 message:@"You will jump to a when you click 'Yes,Go',or click 'No,I am not' for exit" 
 delegate:nil 
 cancelButtonTitle:@"Yes,Go"
     cancelButtonTitle:@"No,I am not" 
 otherButtonTitles:nil];
 [alert show];
 [alert release];

正如它的描述,当我点击'Yes,Go'时我想跳转到a,如果我点击'No,I am not',这个应用程序将被关闭

那该怎么办呢?

谢谢

【问题讨论】:

  • 你为什么要写两次cancelButtonTitle?

标签: iphone objective-c ios uibutton uialertview


【解决方案1】:

您可以在警报视图委托中处理事件

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

在这里检查按钮索引并做你想做的事。

【讨论】:

    【解决方案2】:

    首先像下面这样写你的 UIAlertView,

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"You will jump to a when you click 'Yes,Go',or click 'No,I am not' for exit" 
                              delegate:self 
                              cancelButtonTitle:@"Yes,Go"
                              otherButtonTitles:@"No,I am not" 
                              ,nil];
        [alert show];
        [alert release];
    

    然后你可以处理用户点击哪个按钮,如下代码:

     -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {   
        if(buttonIndex ==0)
        {
            //handle it for "Yes,Go"
        }
    
        else if (buttonIndex ==1)
        {
            //handle it for "No,I am not"
        }   
    }
    

    【讨论】:

      【解决方案3】:

      我们在这里遗漏了很多细节来回答我认为的这个问题。你的程序的结构是什么?如何显示 xib 文件等。

      【讨论】:

      • 我的意思是我只是想要这样的功能,如果我点击是,它将跳转到一个 xib 文件,如果我点击否,应用程序将被关闭,所以......谢谢跨度>
      最近更新 更多