UIImagePickerController 未在 iPhone SDK 的 viewDidLoad 中加载
我试图在我的视图控制器之一加载后立即显示 UIImagePickerController 。我希望用户不必按下按钮,因此我重写了 viewDidLoad 方法,如下所示:
- (void)viewDidLoad {
[super viewDidLoad];
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.allowsImageEditing = YES;
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
它会编译并运行,但是当加载视图控制器时,不会显示图像选择器。例如,如果我将其附加到按钮的事件,则该代码可以正常工作。有任何想法吗?
谢谢。
I'm trying to show a UIImagePickerController as soon as one of my view controller loads. I'd like to this without the user having to press a button so I overrode the viewDidLoad method as follows:
- (void)viewDidLoad {
[super viewDidLoad];
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.allowsImageEditing = YES;
imagePickerController.delegate = self;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
This compiles and runs, however when the view controller is loaded the image picker is not displayed. This code works fine if I attach it to an event of a button for example. Any ideas?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有同样的问题但解决了。尝试使用
它会在其他所有内容加载后加载。
I had the same problem but solved it. Try using
It will load just after everything else loads.
尝试将代码放入
That Even 中,每次视图出现在屏幕上时都会运行(包括在您关闭 UIImagePicker 后出现时),因此您可能需要添加一个 BOOL 值以使其仅在第一次显示时发生,或者当您需要时(即不在关闭模态视图之后)。
Try putting the code in
That even runs every time the view appears on the screen though (including when it appears after you dismiss the UIImagePicker), so you might have to add a BOOL value to make it only happen the first time it shows, or when you want it (i.e. not after dismissing a modal view).
看来viewDidLoad使用presentModalViewController:animated:还为时过早。我建议分叉一次性计时器以从下一次运行循环迭代中调用该方法:
添加以下方法:
It seems that viewDidLoad is too early to use presentModalViewController:animated:. I'd sugget to fork off a one-shot timer to call the method from next run loop iteration:
add the following method: