[英]How to get top view controller when UIImagePickerController is presented?
[英]How do I open a UIImagePickerController from a presented view controller?
在問題底部更新
這是我想要做的:
主ViewController打開一個新的ViewController(我不需要導航欄,所以我必須做這個模態嗎?)然后打開相機。
在主視圖控制器中,我可以在按下按鈕時調用它:
CameraProcessViewController *controller = [[CameraProcessViewController alloc] initWithNibName:@"CameraProcessViewController" bundle:nil];
[self presentModalViewController:controller animated:NO];
這將打開下一個控制器。 在viewDidLoad方法的下一個控制器中,我有:
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate: self];
[imagePicker setAllowsEditing:NO];
[self presentModalViewController:imagePicker animated:YES];
NSLog(@"Has camera");
} else {
NSLog(@"Has no camera");
}
我已經嘗試了presentModalViewController和presentViewController以及主視圖控制器和該子視圖之間兩者的每種組合,但是相機從未打開過。 當我將相機代碼移入主視圖控制器時,它可以正常打開。
我看了又看,什么也沒說是為什么。
謝謝!
UPDATE我發現在viewDidLoad方法中我可以這樣稱呼:
[self performSelector:@selector(openCamera) withObject:nil afterDelay:0];
它加載它就好了。 這樣可以嗎?還是不建議這樣做? 似乎有點hacky!
viewDidLoad
不是執行此操作的正確位置。 您可以嘗試viewWillAppear
但這可能還為時過早。 否則, viewDidAppear
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.