2

所以我有一个 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;
    }
4

3 回答 3

0

[自选图像];

-(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];
}
于 2013-07-19T00:05:44.630 回答
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];        
}
于 2013-07-18T06:17:30.447 回答
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];
}
于 2013-07-18T06:05:04.040 回答