0

我今天看到一个奇怪的行为。我试图从一个名为“BloodWingViewController(viewcontroller 的子类)”的视图控制器中打开 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”并尝试打开选择器,那么它根本不起作用。没有选择器打开。你能解释一下这背后的原因吗?以及如何克服这个问题,因为我必须从已通过模态 Seague 连接执行的视图控制器打开选择器。

如果让您感到困惑,请原谅我的英语: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 * 选择器;}

  • (IBAction)onPhotoPickerClick:(id)sender;

@property (retain, nonatomic) UIImagePickerController * 选择器;

@结尾

现在,当我使用 push segue 连接来到 EditStudentViewController 时,onPhotoPickerClick 正在工作,这意味着 photolibary 出现了,我可以选择图像。但是当我从以前的视图控制器来到 EditStudentViewController 时,photolibary 根本没有出现。

谢谢。

4

0 回答 0