2011-07-26 61 views
1

我一直试图让我的应用程序选择从照片库中的照片,然后显示它的时候,它的工作在不同的项目很好,但在这一个应用程序运行正常,但当我按那应该弹出画廊的UIButton,我得到的main.m错误SIGABRT上INT retVal的= UIApplicationMain(ARGC,ARGV,无,无);的Xcode 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,但我不知道是什么导致该按钮来使我的错误。

任何帮助是极大的赞赏。

+0

你能发布有关堆栈跟踪任何控制台输出? –

+0

2011-07-26 22:08:44.016的刑期[6923:207] - [视图控制器selectExistingpicture]:无法识别的选择发送到实例0x4b46c20 2011-07-26 22:08:44.020项目[6923:207] ***终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因:“ - [视图控制器selectExistingpicture]:无法识别的选择发送到实例0x4b46c20” ***在第一掷调用堆栈: –

+0

是一个iPad或iPhone应用??? – makboney

回答

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]; 

看看我是如何设置的

+0

我试过仅更换picker.sourcetype并与你整个事情,但我仍然得到了同样的问题(我没有得到的NSLog说在我的控制台错误)。 –

+0

好吧,我想试试这个,放了的NSLog进入if语句,看看它甚至尝试运行的相册,把的NSLog权之初 – Jacob

+0

好吧,我固定selectExistingpicture和selectExistingPicture得到它的问题在访问照片库的代码中获得一行SIGABRT,所以我恢复了我的方法,现在它可以正常工作,感谢您的帮助! –

0

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

可能出现的问题:

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

  2. 你在几个地方写了selectExistingpicture而不是selectExistingPicture(低位与大写P)。

0

selectExistingpicture!= selectExistingPicture ...

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

0

正如其他人所指出的,你有一个错字(上selectExistingPicture不正确的情况下),错误消息为你指出正确的有:

原因:“ - [视图控制器selectExistingpicture]:无法识别 选择