【问题标题】:Dismissing UIImagePickerController from UITabBarController从 UITabBarController 中关闭 UIImagePickerController
【发布时间】:2010-05-21 14:38:14
【问题描述】:

我有一个标签栏应用程序,其中一个标签使用导航控制器在一系列视图中移动。在最终视图上,有一个添加照片的按钮,它呈现了一个 UIImagePickerController。到目前为止,一切都很好 - 但是当我完成选择图像或取消操作时,会加载上一个视图,但没有标签栏。我确定我缺少一些基本的东西,但是任何关于如何正确释放 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];

【问题讨论】:

    标签: iphone objective-c cocoa


    【解决方案1】:

    您不需要将选取器视图添加为窗口的子视图。 当用户按下按钮时,执行类似于以下 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];
    
    
    }
    

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

    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)imagePicker 
    { 
    
        [[imagePicker parentViewController] dismissModalViewControllerAnimated:YES]; 
    
    } 
    

    【讨论】:

    • 这是一个巨大的帮助,既对眼前的问题,也对我理解模态视图控制器。非常感谢。
    • 好吧,如果答案有帮助,那么您可以考虑投票,并且可能会接受它作为确定的 ;-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多