【问题标题】:How to respond to UIImagePickerController Generated UIAlertView如何响应 UIImagePickerController 生成的 UIAlertView
【发布时间】:2013-07-09 06:50:45
【问题描述】:

我正在使用 UIImagePickerController 从我的应用程序中捕获视频,并且我已将视频最长持续时间设置为 30 秒。当达到 30 秒的限制时。我收到一条警告消息“已达到最大视频录制限制”由 UIImagePickerController 生成,它会停止捕获视频。

我想要的是响应达到 30 秒限制时自动生成的警报。当按下该警报的“确定”按钮时,我想执行一些操作。我已经实现了 UIAlertView 的所有委托方法,但是当我按下 OK 按钮时它确实会出现在任何方法中。

请帮助我如何响应该警报?

【问题讨论】:

  • 请显示您用于生成警报的代码
  • 你能得到一些UIImagePickerControllerDelegate的方法在时间超过时调用吗?例如imagePickerController:didFinishPickingMediaWithInfo:
  • UIAlertViewDelegateProtocol 是正确答案,只需确保设置委托并使用断点检查索引是否对应“OK”。
  • 在 UIAlertViewDelegateProtocol 实现方法'- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex' ;和按钮索引将被按下按钮索引。欲了解更多信息,请访问link
  • 正如我所说,我已经实现了 UIAlertview 的所有委托方法,但它没有响应任何这些方法,因为我没有通过我的代码生成该警报。当达到 30 秒限制时,它由 UIImagePickerController 自身生成。而且我无法将那个特定的 alert'delegate 设置为 self。

标签: ios uiimagepickercontroller uialertview


【解决方案1】:

你不能使用所有这些委托方法,因为你没有启动UIAlertView所以你不能设置他的委托......

我唯一能想到的就是做一些事情,比如听UIWindowDidBecomeVisibleNotification 来检测何时显示警报,以及听UIWindowDidBecomeHiddenNotification 通知来检测它何时消失。

您应该知道,对于使用自己的 UIWindow 的所有类型的组件(例如 UIActionSheet 或键盘)都会触发这些通知,因此您需要确保这是正确的(也许检查一下是否有是其中一个子视图中的 UIAlertView..)

【讨论】:

    【解决方案2】:

    将自己设置为UIImagePickerController 的代表,并实施UIImagePickerControllerDelegate 协议。具体方法如下:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)
    

    【讨论】:

    • Nops..您的解决方案将不起作用。一点澄清。 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *) 在达到 30 秒时间限制时立即调用。当我按下 UIAlertview 的 OK 按钮时,它没有被调用。我想在按下 OK 按钮后立即执行一些任务。
    • 在这种情况下,我开始认为@Eyal 的答案是你能得到的最接近的答案。
    【解决方案3】:

    使用UIAlertViewDelegateProtocol

    表单文档

    alertView:clickedButtonAtIndex:

    当用户发送给委托人 单击警报视图上的按钮。

    • (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 参数alertView 包含按钮的警报视图。 buttonIndex 按钮的索引 被点击了。按钮索引从 0 开始。 讨论 调用此方法后接收器会自动关闭。

    可用性 适用于 iOS 2.0 及更高版本。在 UIAlertView.h 中声明

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
        if (buttonIndex == 0)
        {
            // do stuff for button index 0,ie cancel button and sthe same for other button  indeces
        }
    }
    

    【讨论】:

      【解决方案4】:

      请参考本教程:http://mobile.tutsplus.com/tutorials/iphone/uialertview/你可以更理想:

      UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Hello World!"
                                                        message:@"This is your first UIAlertview message."
                                                       delegate:self
                                              cancelButtonTitle:@"Button 1"
                                              otherButtonTitles:@"Button 2", @"Button 3", nil];
      [message show];
      
      
      - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
      {
          NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
          if([title isEqualToString:@"Button 1"])
          {
              NSLog(@"Button 1 was selected.");
          }
          else if([title isEqualToString:@"Button 2"])
          {
              NSLog(@"Button 2 was selected.");
          }
          else if([title isEqualToString:@"Button 3"])
          {
              NSLog(@"Button 3 was selected.");
          }
      }
      

      【讨论】:

      • 我没有在我的代码中按语法创建警报......它是由 UIImagePickerController 自动创建的。
      • - (void)picturePopup:(UIAlertView *)picturePopup clickedButtonAtIndex:(NSInteger)buttonIndex 使用这个方法可能是它的工作。
      • 它不是 UIAlertView 的委托方法。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 1970-01-01
      相关资源
      最近更新 更多