0

ボタンのクリックから UIImagePickerController を表示しようとしています。ボタンをクリックすると、次の行に SIGABRT が表示されます。

[self presentModalViewController:camera animated:YES];

コードブロックから:

camera = [[UIImagePickerController alloc]init];
[camera setSourceType:UIImagePickerControllerSourceTypeCamera];
[camera setDelegate:self.view];
camera.showsCameraControls = NO;
camera.navigationBarHidden = YES;
camera.wantsFullScreenLayout = YES;
camera.toolbarHidden = YES;
camera.cameraOverlayView = bottomArrow;
[self presentModalViewController:camera animated:YES];

そのように定義されcameraたの名前はどこにありますか:UIImagePickerController

UIImagePickerController *camera;

@interface。私のインターフェース宣言は次のとおりです。

@interface cameraViewController : UIViewController  <UINavigationControllerDelegate, UIImagePickerControllerDelegate> {

誰かが私が間違っていることを見ることができますか?

4

3 に答える 3

2

@Vikings による良い点に加えて、使用する前にデバイスにカメラがあるかどうかを常に確認してください。

if ([UIImagePickerController
     isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
    [camera setSourceType:UIImagePickerControllerSourceTypeCamera];
} else {
    [camera setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
于 2012-09-26T23:11:36.530 に答える
1

Navigation Controller Delegate と Image Picker Controller Delegate の両方を使用していることを確認してください。イメージ ピッカーは実際にはナビゲーション コントローラーであるため、そのデリゲートを実装する必要があります。

 @interface YourViewController : UITableViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

また、デリゲートをビューではなくビュー コントローラーに正しく設定します。

camera.delegate = self;

デリゲートは、ビュー コントローラーのビューではなく、ビュー コントローラーに設定する必要があります。

以下のコードをチェックしてください。

(1) ナビゲーションバーがないので非表示にする必要はありません

(2) ツールバーがないので非表示にする必要はありません

(3) Modal View Controller は常にフルスクリーンを使用するため、wantsFullScreenLayout を指定する必要はありません。

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.showsCameraControls = NO;
// Comment out the line below to make sure it is not causing a problem.
// This just expects a view, so if bottomArrow is a view you should be fine
picker.cameraOverlayView = bottomArrow;
[self presentModalViewController:picker animated:YES];

また、viewDidLoad でこのコードを読み込んでいることに気付きませんでした。View Controller 自体が遷移を完了していないため、クラッシュします。別の遷移を開始することはできません。代わりに、同じ効果のために viewDidAppear を使用します。

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:YES];
    // Place code here
}
于 2012-09-26T23:01:31.287 に答える
0

コードを viewDidLoad に配置しないでください。1 つの IBAction を作成し、その関数内にコードを配置してください。

ビューコントローラーにデリゲートを設定します。そして.hファイルであなたが書いたことを確認してください

<UIImagePickerControllerDelegate>

[camera setDelegate : self];
于 2012-09-27T04:48:20.527 に答える