UiimagepickerView:在呈现uiimagepickerview时应用程序崩溃了?

时间:2014-12-26 07:09:50

标签: ios objective-c xcode uiimagepickercontroller

我有以下代码供图片选择器使用:

- (void)actionSheet:(UIActionSheet *)popup clickedButtonAtIndex:(NSInteger)buttonIndex {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;

switch (popup.tag) {
    case 1: {
        switch (buttonIndex) {
            case 0:
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                [self presentViewController:picker animated:YES completion:NULL];
                break;
            case 1:
                picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                [self presentViewController:picker animated:YES completion:NULL];
                break

同时出现以下错误:

[__NSCFArray pointSize]: unrecognized selector sent to instance 0x6a5e640
2014-12-26 12:04:50.304 AssetDB[78872:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray pointSize]: unrecognized selector sent to instance 0x6a5e640'
*** First throw call stack:
(0x134f052 0x1903d0a 0x1350ced 0x12b5f00 0x12b5ce2 0x30168b 0x310aae 0x3134d7 0x3133dd 0x313423 0x313e88 0x2d64b0 0x3137f7 0x2db322 0x1350e72 0xfa92d 0x104827 0x104922 0x2d4f47 0x3710b6 0x2d64b0 0x371087 0x370dbd 0x373b32 0x373b97 0x36539c 0x3727fc 0x2d86ec 0x2d4c72 0x2d9a4f 0x2d372b 0x341116 0x5804c7 0x369427 0x36958c 0x8fc2 0x65aa1f 0x1350ec9 0x29f5c2 0x29f55a 0x344b76 0x34503f 0x3442fe 0x2c4a30 0x2c4c56 0x2ab384 0x29eaa9 0x223cfa9 0x13231c5 0x1288022 0x128690a 0x1285db4 0x1285ccb 0x223b879 0x223b93e 0x29ca9b 0x29a8 0x2905)

终止调用抛出异常

2 个答案:

答案 0 :(得分:0)

它有点旧,但最近我遇到了类似的问题。 检查你是否有某个地方

NSFontAttributeName: "Some string"

这应该替换为

NSFontAttributeName: UIFont(name: "Some-font", size: yourSize)

这对我有用。

答案 1 :(得分:-2)

- (IBAction)OnClickbutton:(id)sender {

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle: nil
                                                         delegate: (id)self
                                                cancelButtonTitle: @"Cancel"
                                           destructiveButtonTitle: nil
                                                otherButtonTitles: @"Take a new photo", @"Choose from existing", nil];
[actionSheet showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];

if  ([buttonTitle isEqualToString:@"Take a new photo"]) {
    [self takeNewPhotoFromCamera];
}
if ([buttonTitle isEqualToString:@"Choose from existing"]) {
    [self choosePhotoFromExistingImages];
}


}

- (void)takeNewPhotoFromCamera
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.editing = YES;
imagePickerController.delegate = (id)self;

[self presentViewController:imagePickerController animated:YES completion:nil];

}

 -(void)choosePhotoFromExistingImages
 {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary])
{
    UIImagePickerController *controller = [[UIImagePickerController alloc] init];
    controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    controller.allowsEditing = NO;
    controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypePhotoLibrary];
    controller.delegate = (id)self;
    controller.navigationBar.barStyle = UIBarStyleBlackTranslucent; // Or whatever style.

    [self.navigationController presentViewController: controller animated: YES completion: nil];
}
}