访问照片库时Xcode SIGABRT

时间:2011-07-26 21:44:32

标签: objective-c ios camera sigabrt

我一直试图让我的应用程序从照片库中选择一张照片,然后显示它,它在一个不同的项目中运行良好,但在这一个应用程序运行正常,但当我按下假设的UIButton为了调出画廊,我在main.m上得到了错误SIGABRT int retVal = UIApplicationMain(argc,argv,nil,nil);

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

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 个答案:

答案 0 :(得分: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];

看看我如何设置

答案 1 :(得分:0)

您的问题与照片库无关。它可能永远不会首先执行selectExistingPicture

可能出现的问题:

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

  2. 您在少数地方写selectExistingpicture而不是selectExistingPicture(低于大写P)。

答案 2 :(得分:0)

selectExistingpicture!= selectExistingPicture ...

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

答案 3 :(得分:0)

正如其他人所说,你有一个拼写错误(selectExistingPicture上的错误案例),在错误信息中就为你注明了:

  

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