iPhone dev noob问题:在应用程序启动时明确调用操作

时间:2010-02-26 21:16:28

标签: iphone objective-c camera

我刚开始进入iPhone开发阶段。我一直在混搭书籍中的教程和资料,以便让我的方向变得更好。我来自PHP和Java背景...... Objective-C有点古怪。但是,我最好把脚弄湿了。

基本上,我有这些行动。在我看来,getPhoto绑定了几个UIBarButtonItem。

-(IBAction) getPhoto:(id) sender {
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if((UIBarButtonItem *) sender == choosePhoto) {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    } else {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    }

    [self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    theimageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}

我的目标是在应用程序启动后调用相同的操作,自动打开相机。我该怎么做呢?

1 个答案:

答案 0 :(得分:3)

编辑:

根据this SO question,您应该将其放在viewWillAppearviewDidAppear


在app delegate中为ApplicationDidFinishLaunching方法添加类似的方法。

最好将呼叫置于根视图控制器的ViewDidLoad