I met a problem on using camera by scratch on iphone. Other people's code just run fine on my 3GS, but my code doesn't.
When I implemented a UIViewController
controll开发者_Python百科er, and I add the following code in viewdidload
:
UIImagePickerController *picker = [UIImagePickerController alloc] init];
picker.source = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self; //Previously added all the delegate properly
[self presentModalViewController:picker animated:YES];
Nothing comes out. I checked in the debugger, it shows that the picker is allocated, but here is the major difference between my and success one.
picker._imagepickerflag.visible = 0; //others show 1;
picker.UINavigationController._containerView: 0x0 ; // others have value.
Can anyone help me on this, is there something wrong?
Thank you.
UIImagePickerController *picker = [UIImagePickerController alloc] init];
Above code is wrong. It should be
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
This below is also wrong.
picker.source = UIImagePickerControllerSourceTypeCamera;
it should be
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
And you should release it once it has been presented.
[picker release];
Hope that helps.
精彩评论