2011-12-20 6 views
23

Assigning to id<UINavigationControllerDelegate,UIImagePickerControllerDelegate> from incompatible type CameraViewController* ostrzegawczy pokazuje blisko picker.delegate = self; liniiPrzypisanie do 'id <UINavigationControllerDelegate, UIImagePickerControllerDelegate>' z niekompatybilnego typu 'CameraVIewController *'”

-(IBAction) getPhoto:(id) sender { 
UIImagePickerController * picker = [[UIImagePickerController alloc] init]; 
picker.delegate = self; 

if((UIButton *) sender == takePhoto) { 
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
} else { 
    //picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
} 

[self presentModalViewController:picker animated:YES]; 

}

+0

[This] [1] to najlepsza odpowiedź, którą założyłem na to pytanie. [1]: http://stackoverflow.com/questions/4727895/iphone-uiimagepickercontrollerdelegate-inheritance –

+2

Teraz zauważyłem, że trzeba również przypisać UIViewController do protokołu UINavigationControllerDelegate, ponieważ dokumentacja mówi, że to dla UIImagePickerControllerDelegate: @property (nonatomic, assign) id delegate; oznacza to, że musisz przypisać do obu tych protokołów. –

Odpowiedz

7

The documentation for UIImagePickerController mówi, że delegat musi wdrożyć protokół UIImagePickerControllerDelegate. Twój CameraViewController albo nie implementuje tego protokołu, albo nie deklaruje, że robi to w swoim nagłówku.

+7

Rewizja. Powinieneś także dostosować się do 'UINavigationControllerDelegate' – Honey

80

Należy pamiętać, że należy użyć zarówno protokołów UIImagePickerControllerDelegate, jak i UINavigationControllerDelegate, aby użyć próbnika obrazu.

+2

Ten zrobił to dla mnie. Dzięki! – Mike

+3

To powinno być zaznaczone poprawnie - Większość ludzi oczekuje, że UIImagePickerControllerDelegate jest wymagany, ale przeoczyć, że to również pytanie o UINavigationControllerDelegate. Dzięki za odpowiedź. – Adama

+2

Dlaczego, na litość boską, potrzeba UINavigationControllerDelegate? To prawdziwa tajemnica. – fatuhoku

13

Wystarczy dodać oba protokoły.

@interface MyViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> 

Następnie ustaw delegata w sposób oczywisty. :)

Powiązane problemy