gpt4 book ai didi

iphone - 从 UITabBarController 中消除 UIImagePickerController

转载 作者:行者123 更新时间:2023-12-03 17:36:53 25 4
gpt4 key购买 nike

我有一个选项卡栏应用程序,其中一个选项卡使用导航 Controller 在一系列 View 中移动。在最终 View 上,有一个添加照片的按钮,其中呈现了一个 UIImagePickerController。到目前为止,一切都很好 - 但是当我完成选择图像或取消操作时,会加载上一个 View ,但没有选项卡栏。我确信我错过了一些基本的东西,但是任何有关如何正确释放 UIImagePickerController 的建议将不胜感激。代码如下:

ImagePickerViewController *aController = [[ImagePickerViewController alloc];             initWithNibName:@"ImagePickerViewController" bundle:[NSBundle mainBundle]];  
[self presentModalViewController:aController animated:YES];
[aController release];

//viewDidLoad
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;

if([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

[window addSubview:imagePickerController.view];

//ImagePickerViewController imagePickerControllerDidCancel - FinalViewController is the last view in the stack controlled by a navigation controller which contains the button to present the UIImagePickerController

[picker dismissModalViewControllerAnimated:YES];
FinalViewController *aController = [[FinalViewController alloc initWithNibName:@"FinalViewController" bundle:[NSBundle mainBundle]];
[picker presentModalViewController:aController animated:YES];
[aController release];

最佳答案

您不需要将选取器 View 添加为窗口的 subview 。当用户按下按钮时,执行类似于以下 snapPicture 方法的操作:

- (IBAction) snapPicture{


UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
// Set up the source
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.allowsEditing = NO;
}
else {
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

ipc.delegate = self;
[self presentModalViewController:ipc animated:YES];
[ipc release];


}

然后,实现选择器委托(delegate)方法。在这里我只是展示其中之一来展示如何关闭选择器。

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)imagePicker 
{

[[imagePicker parentViewController] dismissModalViewControllerAnimated:YES];

}

关于iphone - 从 UITabBarController 中消除 UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2883016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com