1

我一直在尝试让我的应用程序从照片库中选择一张照片然后显示它,它在另一个项目中运行良好,但是在这个项目中应用程序运行良好但是当我按下应该显示的 UIButton画廊,我在 int retVal = UIApplicationMain(argc, argv, nil, nil); 上的 main.m 中收到错误 SIGABRT;

正如我所说,这在过去运行良好,所以我不知道为什么现在不行,这是与错误相关的代码部分,我只是发布它,因为我有很多代码这样更容易。

视图控制器.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

视图控制器.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!= selectExistingPicture...

那就是你声明selectExistingpicture然后定义selectExistingPicture这就是你的自动完成selectExistingpicture为你选择的原因,因为它存在于你的.h文件中,这种不匹配会导致编译器警告......将所有实例更改为正确的camelCased selectExistingPicture,你会没事的...... . 至少那个错误会消失。

于 2011-07-27T20:54:14.513 回答
0

正如其他人指出的那样,您有一个错字(selectExistingPicture 上的大小写不正确),在错误消息中为您指出:

原因:'-[ViewController selectExistingpicture]:无法识别的选择器

于 2011-07-27T21:01:22.207 回答
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

可能出现的问题:

  1. 视图控制器不是一个实例,ViewController因为您没有在 IB 中指定正确的类。

  2. 您在一些地方写selectExistingpicture而不是selectExistingPicture(小写与大写 P)。

于 2011-07-27T08:40:52.540 回答