dismissViewControllerAnimated神秘地为iPhone工作

时间:2013-07-11 21:02:52

标签: iphone ios6 uiviewcontroller dismiss

所以我有一个iPhone应用程序选择和图像然后弹出窗口。您可以选择取消忽略弹出窗口的弹出窗口,这是以下方法的作用。当我测试我的应用程序时,我可以从照片库中选择一个图像,让图像选择器被解雇,但然后imagePicker会重新启动。但是,当我测试我的应用程序时,以下方法的注释没有被打印,我没有在别处执行dimiss调用,所以怎么可能发生这种情况?

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

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
    if ([popoverController isPopoverVisible]) {
        NSLog(@"imagePickerControllerDidCancel called for iPad");
        [popoverController dismissPopoverAnimated:YES];
    }
}
else {
    NSLog(@"imagePickerControllerDidCancel called for iPhone");
    [self dismissViewControllerAnimated:YES completion:nil];
}

[picker release];
[self pickImage];
}

用于呈现视图控制器的代码:

switch (buttonIndex) {
    case 0: { //photo library
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
            UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;
            imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
                if ([popoverController isPopoverVisible]) {
                    [popoverController dismissPopoverAnimated:YES];
                }
                else {
                    popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
                    popoverController.delegate = self;
                    [popoverController presentPopoverFromRect:CGRectMake( 250, -50, 320, 480 )
                                                       inView:[self view]
                                     permittedArrowDirections:UIPopoverArrowDirectionUp
                                                     animated:YES];
                }
            }
            else {
                [self presentViewController:imagePicker animated:TRUE completion:nil];
            }
        } else {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Photo library is empty or unavailable" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
        }
        break;
    }

3 个答案:

答案 0 :(得分:0)

请为iphone尝试此代码,然后检查

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    [self presentModalViewController:imagePicker animated:TRUE];
}

答案 1 :(得分:0)

尝试这个

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
    [popoverController dismissPopoverAnimated:true];
    [picker dismissModalViewControllerAnimated:YES];

}

imagePickerControllerDidCancel:方法,如下方...

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

        [popoverController dismissPopoverAnimated:true];
        [picker dismissModalViewControllerAnimated:YES];        
}

答案 2 :(得分:0)

[self pickImage];

in

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

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
    if ([popoverController isPopoverVisible]) {
        NSLog(@"imagePickerControllerDidCancel called for iPad");
        [popoverController dismissPopoverAnimated:YES];
    }
}
else {
    NSLog(@"imagePickerControllerDidCancel called for iPhone");
    [self dismissViewControllerAnimated:YES completion:nil];
}

[picker release];
[self pickImage];
}