2013-01-18 13 views
6

Pracuję na iPadzie 4 z iOS 6.0.Awaria interfejsu UIIMagePickerController podczas zamykania na iPadzie ios 6.0

mam ViewController (MyPickerController) ze inicjalizujący

- (id)init 
{ 
   self = [super init]; 
   if (self) { 
       _picker = [[UIImagePickerController alloc] init]; 
       _picker.delegate = self; 
       _picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
       [self.view addSubview:_picker.view]; 
   } 
   return self; 
} 

zaimplementować następujące UIPickerControllerDelegate metody dimiss MyPickerController:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 
   [self dismissViewControllerAnimated:YES completion:nil]; 
} 

dobrze, że inny sterownik widok wykazały modalne w FormSheetStyle i po dotknięciu przycisku chcę pokazać MyPickerController z następującym kodem:

MyPickerController * pickerVC = [[MyPickerController alloc] init]; 
[self presentViewController:pickerVC animated:YES completion:nil]; 

W moim AppDelegate Mam następujący sposób totation:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { 
    
   return (NSUInteger)[application supportedInterfaceOrientationsForWindow:window] | (1<<UIInterfaceOrientationPortrait); 
    
} 

Kiedy dotknij przycisk UIIMagePicker odwołać do MyPickerController, aplikacja ulega awarii z powodu następującego błędu:

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation! 

Czytając pytania związane na stackoverflow, tworzę także następującą kategorię UIImagePickerController:

@implementation UIImagePickerController (NonRotating) 

- (BOOL)shouldAutorotate 
{ 
   return NO; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
   return UIInterfaceOrientationMaskPortrait; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
   return UIInterfaceOrientationMaskPortrait; 
} 

@end 

Dziękujemy!

+0

dlaczego dodać widok próbnika jako podrzędny twojego widok? –

Odpowiedz

2

Spróbuj to zrobić ..

Jeśli kontroler widoku jest wewnątrz UINavigationController, należy użyć tę kategorię do navigationcontroller:

@implementation UINavigationController (autorotate) 

- (NSUInteger)supportedInterfaceOrientations{ 
     return UIInterfaceOrientationMaskAll; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ 
     return UIInterfaceOrientationMaskPortrait; 
} 


@end 
Powiązane problemy