1

アプリケーションでフォトギャラリーから写真を選択して表示しようとしましたが、別のプロジェクトでは問題なく動作しましたが、このプロジェクトではアプリケーションは正常に動作しますが、表示されるはずの UIButton を押すとギャラリーでは、int retVal = UIApplicationMain(argc, argv, nil, nil); の main.m でエラー SIGABRT が発生します。

私が言ったように、これは過去にうまく機能していたので、なぜ今はうまくいかないのかわかりません。ここにエラーに関連するコードの部分があります。コードがたくさんあるので、それを投稿するだけですこの方法は簡単です。

ViewController.h

#import <UIKit/UKit.h>

@interface ViewController : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
    //Blah blah blah
}

//Blah blah blah
-(IBAction) selectExistingpicture;
@property (nonatomic, retain) IBOutlet UIImageView *theImageView;

//Blah blah blah

@end

ViewController.m

#import "ViewController.h"

@implementation ViewController

@synthesize theImageView;

-(IBAction) selectExistingPicture
{
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        [self presentModalViewController:picker animated:YES];
        [picker release];
    }
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage : (UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    theImageView.image = image;
    [picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)  picker
{
    [picker dismissModalViewControllerAnimated:YES];
}

selectExistingPicture を UIButton にリンクしましたが、そのボタンが原因でエラーが発生する原因がわかりません。

どんな助けでも大歓迎です。

4

4 に答える 4

0

あなたの問題はフォトギャラリーとは何の関係もありません。selectExistingPictureそもそも実行されることはおそらくないでしょう。

考えられる問題:

  1. ViewControllerIBで正しいクラスを指定しなかったため、ViewControllerはのインスタンスではありません。

  2. いくつかの場所で(小文字と大文字のP)selectExistingpictureの代わりに書き込みます。selectExistingPicture

于 2011-07-27T08:40:52.540 に答える
0

カメラロールの使い方はこちら

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];

    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, (NSString *) kUTTypeMovie,
                                        nil];

    imagePickerController.delegate = self;

    [self presentModalViewController:imagePickerController animated:YES];


}

else {
    NSLog(@"Error");

}

私があなたのもので間違っていると思うことは

        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

どちらであるべきか

        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

また、あなたは行方不明のようです

imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, (NSString *) kUTTypeMovie,
                                    nil];

私のセットアップ方法を見てください

于 2011-07-27T07:23:47.833 に答える
0

selectExistingpicture!= selectExistingPicture...

つまり、宣言してselectExistingpicture定義するselectExistingPictureと、オートコンプリートが選択する理由がselectExistingpicture.h ファイルに存在するため、この不一致によりコンパイラの警告が発生します...すべてのインスタンスを適切な camelCased に変更selectExistingPictureすると問題ありません. . まあ、少なくともそのエラーはなくなります。

于 2011-07-27T20:54:14.513 に答える
0

他の人が指摘したように、タイプミス (selectExistingPicture の大文字と小文字が正しくない) があり、エラー メッセージに記載されています。

reason: '-[ViewController selectExistingpicture]: 認識されないセレクター

于 2011-07-27T21:01:22.207 に答える