UIImagePickerController вызывает сбой на ios5 - PullRequest
0 голосов
/ 28 марта 2012
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.

UINavigationController *HomeNav = [[UINavigationController alloc] initWithRootViewController:[[HomeController alloc] init]];

[HomeNav.navigationBar setTintColor:[UIColor clearColor]];

CustomTabBar *tabBar = [[CustomTabBar alloc] init];
tabBar.buttonImages = [NSArray arrayWithObjects:@"t1.png" , nil];
tabBar.hightLightButtonImages = [NSArray arrayWithObjects:@"th1.png",  nil];
tabBar.viewControllers = [NSArray arrayWithObjects:HomeNav , nil];
self.tabBarController = tabBar;
[tabBar release];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];

return YES;
}

в представлении HomeController, есть одна кнопка, если нажать кнопку, которую я называю `AViewController.

-(IBAction)tapButtonA:(id)sender;
{
    [self.navigationController pushViewController:AViewController animated:YES];
}

, есть также кнопка в представлении AViewController.

если я нажму кнопку, я позвоню UIImagePickercontroller

-(IBAction)tapButtonB:(id)sender;
{
 UIImagePickerController *picker=[[UIImagePickerController alloc]init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
picker.allowsImageEditing = YES;

[self presentModalViewController: picker animated:NO]; 
}

Если я нажму кнопку отмены UIImagePickerController

-(void)imagePickerControllerDidCancel:(UIImagePickerController*)picker{
[self.presentingViewController dismissModalViewControllerAnimated:YES];
}

, UIImagePicker будет отклонен,но через 1,2 секунды приложение вылетает и отображает

enter image description here

Приветствую любой комментарий

Ответы [ 3 ]

0 голосов
/ 28 марта 2012

Я думаю, что вы хотите:

-(void) imagePickerControllerDidCancel:(UIImagePickerController*)picker {
    [picker.presentingViewController dismissModalViewControllerAnimated:YES];
}
0 голосов
/ 28 марта 2012

попробуйте

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissModalViewControllerAnimated:YES];
}
0 голосов
/ 28 марта 2012

Следующий код решит вашу проблему,

#pragma mark - UIActionsheet Delegate method
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {


                self.imagePicker = [[UIImagePickerController alloc] init];
                self.imagePicker.delegate = self;
                self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
                self.imagePicker.allowsEditing = NO;
                self.imagePicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
                [self presentModalViewController:self.imagePicker animated:YES];
            }
            else{
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                                                message:@"Unable to connect camera." 
                                                               delegate:self cancelButtonTitle:@"Ok" 
                                                      otherButtonTitles:nil];
                [alert show];
            }
            break;
        case 1:

            self.imagePicker = [[UIImagePickerController alloc] init];
            self.imagePicker.delegate = self;
            self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            self.imagePicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
            [self presentModalViewController:self.imagePicker animated:YES];


            break;
        default:
            break;
    }
}




#pragma mark - UIImagePicker Delegate method
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Access the uncropped image from info dictionary
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];


   self.imgForEvent=image;

    //    // Save image
    //     if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
    //         UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    //     }
    [self dismissModalViewControllerAnimated:YES];

}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIAlertView *alert;

    // Unable to save the image  
    if (error)
        alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                           message:@"Unable to save image to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];
    else // All is well
        alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                                           message:@"Image saved to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];
    [alert show];

    [self.imagePicker dismissModalViewControllerAnimated:YES];

}

Этот код может помочь в решении вашей проблемы

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...