在应用打开时加载弹出窗口视图

时间:2014-06-27 21:19:10

标签: ios objective-c

this tutorial之后,我试图制作一个非常简单的iOS视频应用来学习api。该教程告诉我们在视图上放置一个按钮,当按下该按钮时,使用UIImagePickerController api(模式或弹出视图)来显示摄像机控件。对于我的应用程序,我想要显示UIImagePickerController(或者更确切地说是相机功能),而不是在按下按钮时,而是在应用程序打开时。当我将代码移动到viewDidLoad时,我收到此错误消息

2014-06-27 17:04:48.754 VideoBlah[33679:60b] Warning: Attempt to present <UIImagePickerController: 0x1658d4d0> on <ViewController: 0x165be6f0> whose view is not in the window hierarchy!

因此我尝试self.view presentViewController这样

[self.view presentViewController:picker animated:YES completion:NULL];

但是UIView没有选择器presentViewController。

有没有办法让UIImagePickerController的弹出视图控制器在应用程序打开时显示,而不是等待用户显示按钮?

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
//        
//        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
//        picker.delegate = self;
//        picker.allowsEditing = YES;
//        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//        picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
//        
//        [self presentViewController:picker animated:YES completion:NULL];
//    }

}

- (IBAction)captureVideo:(id)sender {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];

        [self presentViewController:picker animated:YES completion:NULL];
    }
}

1 个答案:

答案 0 :(得分:0)

尝试在viewDidAppear中使用此代码。