0

我正在设计的应用程序有问题。

基本上,用户按下一个按钮,将他们带到另一个屏幕,该屏幕可以选择拍照或选择退出的照片,然后通过电子邮件将其发送出去。

这是.h文件

#import <UIKit/UIKit.h>


@interface RoadSafetyViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
  UIImagePickerController *picker1;
UIImagePickerController *picker2;
UIImage *image;
IBOutlet UIImageView *imageView;
}

-(IBAction)TakePhoto;
-(IBAction)ChooseExisting;

@end

和 .m 文件

//
//  RoadSafetyViewController.m
//  Road Safety App
//
//  Created by Information Services on 30/09/13.
//  Copyright (c) 2013 Shellharbour Sity Council. All rights reserved.
//

#import "RoadSafetyViewController.h"
#import "RoadSafetyAppDelegate.h"



@interface RoadSafetyViewController ()

@end

@implementation RoadSafetyViewController

- (IBAction)TakePhoto
{
    picker1 = [[UIImagePickerController alloc] init];
    picker1.delegate = self;
    [picker1 setSourceType: UIImagePickerControllerSourceTypeCamera];
    [self presentViewController:picker1 animated:YES completion:NULL];
    [picker1 release];


}

- (IBAction)ChooseExisting
{
    picker2 = [[UIImagePickerController alloc] init];
    picker2.delegate = self;
    [picker2 setSourceType: UIImagePickerControllerSourceTypePhotoLibrary];
    [self presentViewController:picker2 animated:YES completion:NULL];
    [picker2 release];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [imageView setImage:image];
    [self dismissViewControllerAnimated:YES completion:NULL];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:NULL];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

我在以下行收到 SIGBAT 错误

//
//  main.m
//  Road Safety App
//
//  Created by Information Services on 30/09/13.
//  Copyright (c) 2013 Shellharbour Sity Council. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "RoadSafetyAppDelegate.h"

int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([RoadSafetyAppDelegate class])); //here is where I'm getting a Thread 1: signal SIGBAT error.
    }
}

这是错误的控制台输出。

2013-10-29 09:16:16.870 Road Safety App[907:70b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<HazardIdentificationViewController 0xc32bda0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imageView.'
*** First throw call stack:
(
    0   CoreFoundation                      0x018f85e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0167b8b6 objc_exception_throw + 44
    2   CoreFoundation                      0x019886a1 -[NSException raise] + 17
    3   Foundation                          0x0133c9ee -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
    4   Foundation                          0x012a8cfb _NSSetUsingKeyValueSetter + 88
    5   Foundation                          0x012a8253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
    6   Foundation                          0x0130a70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
    7   UIKit                               0x0068ba15 -[UIRuntimeOutletConnection connect] + 106
    8   libobjc.A.dylib                     0x0168d7d2 -[NSObject performSelector:] + 62
    9   CoreFoundation                      0x018f3b6a -[NSArray makeObjectsPerformSelector:] + 314
    10  UIKit                               0x0068a56e -[UINib instantiateWithOwner:options:] + 1417
    11  UIKit                               0x004fc605 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
    12  UIKit                               0x004fcdad -[UIViewController loadView] + 302
    13  UIKit                               0x004fd0ae -[UIViewController loadViewIfRequired] + 78
    14  UIKit                               0x004fd5b4 -[UIViewController view] + 35
    15  UIKit                               0x005173e2 -[UINavigationController _startCustomTransition:] + 778
    16  UIKit                               0x005240c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
    17  UIKit                               0x00524cb9 -[UINavigationController __viewWillLayoutSubviews] + 57
    18  UIKit                               0x0065e181 -[UILayoutContainerView layoutSubviews] + 213
    19  UIKit                               0x00454267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    20  libobjc.A.dylib                     0x0168d81f -[NSObject performSelector:withObject:] + 70
    21  QuartzCore                          0x022022ea -[CALayer layoutSublayers] + 148
    22  QuartzCore                          0x021f60d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    23  QuartzCore                          0x021f5f40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    24  QuartzCore                          0x0215dae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    25  QuartzCore                          0x0215ee71 _ZN2CA11Transaction6commitEv + 393
    26  QuartzCore                          0x0215f544 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    27  CoreFoundation                      0x018c04ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    28  CoreFoundation                      0x018c041f __CFRunLoopDoObservers + 399
    29  CoreFoundation                      0x0189e344 __CFRunLoopRun + 1076
    30  CoreFoundation                      0x0189dac3 CFRunLoopRunSpecific + 467
    31  CoreFoundation                      0x0189d8db CFRunLoopRunInMode + 123
    32  GraphicsServices                    0x02c989e2 GSEventRunModal + 192
    33  GraphicsServices                    0x02c98809 GSEventRun + 104
    34  UIKit                               0x003e9d3b UIApplicationMain + 1225
    35  Road Safety App                     0x00003222 main + 130
    36  libdyld.dylib                       0x062a170d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

我是 iOS 应用程序开发的新手,不知道这个错误来自哪里。任何识别和纠正错误的帮助都会很棒!

4

1 回答 1

0

imageView您的HazardIdentificationViewController. 如果你在 Interface Builder 中有这个类,请确保你从它中解脱imageView出来。

于 2013-10-29T11:32:45.673 回答