UIImagePickerController:Modal和Push Segue

时间:2012-07-27 12:32:07

标签: iphone objective-c uiimagepickercontroller

我今天看到了一种奇怪的行为。我试图从一个名为“BloodWingViewController(viewcontroller的子类)”的viewcontroler中打开uiimagepickercontroller。以下是显示选择器的代码:

if (self.picker == nil) {   

    [SVProgressHUD showWithStatus:@"Loading picker..."];

    dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

    dispatch_async(concurrentQueue, ^{

        self.picker = [[[UIImagePickerController alloc] init] autorelease];
        self.picker.delegate = self;
        self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        self.picker.allowsEditing = NO;    

        dispatch_async(dispatch_get_main_queue(), ^{
            [self.navigationController presentModalViewController:picker animated:YES];    
            [SVProgressHUD dismiss];
        });

    });        

}  else {        
    [self.navigationController presentModalViewController:picker animated:YES];    
} 

以上代码工作绝对正常,没问题。我看到的奇怪的事情是,如果我通过push seague进入这个所谓的“BllodWingViewController”并尝试打开选择器然后它的工作原理。但是,如果我通过模态塞格再次进入所谓的“BllodWingViewController”并尝试打开选择器,那么它根本不起作用。没有选择器打开。你可以解释一下这背后的原因吗?以及如何克服这个问题,因为我必须从通过模态接口连接执行的viewcontroller打开选择器。

如果它让你感到困惑,抱歉我的英语:P

编辑:

- (IBAction)onPhotoPickerClick:(id)sender {
if (self.picker == nil) {   

    [SVProgressHUD showWithStatus:@"Loading picker..."];

    dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

    dispatch_async(concurrentQueue, ^{

        self.picker = [[[UIImagePickerController alloc] init] autorelease];
        self.picker.delegate = self;
        self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        self.picker.allowsEditing = NO;         

        dispatch_async(dispatch_get_main_queue(), ^{
            [self.navigationController presentModalViewController:picker animated:YES];    
            [SVProgressHUD dismiss];
        });

    });        

}  else {        
    [self.navigationController presentModalViewController:picker animated:YES];    
} 

}

#import <UIKit/UIKit.h>

@interface EditStudentViewController:UIViewController {     UIImagePickerController * picker; }

  • (IBAction为)onPhotoPickerClick:(ID)发送者;

@property(retain,nonatomic)UIImagePickerController * picker;

@end

现在,当我使用推送segue连接来到EditStudentViewController时,onPhotoPickerClick正在工作,意味着photolibary显示,我可以选择图像。但是当我从之前的viewcontroller来到EditStudentViewController时,photolibary根本就没有显示出来。

感谢。

0 个答案:

没有答案