【问题标题】:How to add a confirming pop up window in objective?如何在目标中添加确认弹出窗口?
【发布时间】:2012-07-05 15:04:22
【问题描述】:

像java中的JOptionPane, 当用户做某事时。 我要求确认,例如, 你确定要删除文件吗??或无论如何。 用户确认 然后我检测到用户在两个按钮之间选择了什么 然后我根据用户的选择做一些事情

在目标 c 中有这样的东西吗? 链接请和一些指导方针

谢谢大家

【问题讨论】:

    标签: iphone objective-c xcode ios5


    【解决方案1】:

    您正在寻找 UIAlertView 控制器。

    【讨论】:

    • Alert 视图并不是真正的控制器,只是一个视图,但它确实是他要找的东西
    • 是的,我已经尝试过了,但它们无法检测用户点击的内容
    • 不,你应该使用 UIActionSheet。
    • 实际上您可以同时使用这两种方法,但 UIActionSheet 具有将破坏性按钮着色为红色的优势。在这两种情况下,您都必须知道它们是异步的,因此当弹出窗口出现时,应用程序会继续运行。您必须使用 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonIndex:(NSInteger)buttonIndex 或等效的东西。我认为您现在掌握了所有必要的关键词;)@Dan F:感谢您的更正。
    【解决方案2】:

    我相信你想要UIActionSheet,这是苹果推荐给用户的选择:

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Some Message" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"button To Destroy or nil" otherButtonTitles:@"Choice 1", @"Choice 2", @"Choice 3", nil];
    

    【讨论】:

      【解决方案3】:

      你要做的是检查otherButtonTitles:下的哪个按钮被点击

      类似这样的:

      UIAlertView *yourAlert = [[UIAlertView alloc] initWithTitle:@"Your title" message:@"Some String" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:@"Confirm",nil];  
      
       [yourAlert show];
      

      记得将委托设置为 self。

      然后:

      - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
      
      if (buttonIndex == 0){
      
          //'Dismissing' code here
      
      }
      
      if (buttonIndex == 1){
      
          //Detecting whatever was under otherButtonTitles:
          //Right now it's checking if the user clicked "Confirm" -> So here you can put whatever you need
         NSLog(@"You clicked Confirm");
      
            }
      

      }

      在条件下,您正在检查用户正在单击哪个按钮。

      【讨论】:

        猜你喜欢
        • 2015-11-11
        • 2012-09-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-15
        • 1970-01-01
        相关资源
        最近更新 更多