0

我已经搜索和搜索,尽管关于这个问题有很多主题,但我找不到任何相关的来解决我的问题。如果有人可以请看一下:

我正在使用 xcode 4.6

我在 int retVal 的 main.m 文件中收到错误

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

我的 ReaderSampleViewController.h 文件如下所示:

@interface ReaderSampleViewController
    : UIViewController
    // ADD: delegate protocol
    < ZBarReaderDelegate >
{
    UIImageView *resultImage;
    UITextView  *resultText;

}
@property (nonatomic, retain) IBOutlet UIImageView *resultImage;
@property (nonatomic, retain) IBOutlet UITextView  *resultText;
- (IBAction) scanButtonTapped;
@end

ReaderSampleViewController.m 文件如下所示:

#import "ReaderSampleViewController.h"

@implementation ReaderSampleViewController

@synthesize resultImage, resultText;

- (IBAction) scanButtonTapped
{
    // ADD: present a barcode reader that scans from the camera feed
    ZBarReaderViewController *reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;

    ZBarImageScanner *scanner = reader.scanner;
    // TODO: (optional) additional reader configuration here

    // EXAMPLE: disable rarely used I2/5 to improve performance
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];

    // present and release the controller
    [self presentViewController: reader animated:NO completion:nil];
    [reader release];
}

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    // ADD: get the decode results
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        // EXAMPLE: just grab the first barcode
        break;

    // EXAMPLE: do something useful with the barcode data
    resultText.text = symbol.data;
    // QR CODE TO THE WEBSITE
    #define IS_IPAD    (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    #define IS_IPHONE  (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)




    //----------- STYLE AND AUTO SIZE THE WEB VIEW

    float widthScreen, heightScreen; //xScreen, yScreen
    if(IS_IPAD){

        widthScreen  = 768.0;
        heightScreen = 960.0;
       // xScreen      = 360.0;
       // yScreen      = 500.0;
        UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"LoaderIpad.jpg"]];
        self.view.backgroundColor = background;
        [background release];
    }else{
    //CGRect webFrame = CGRectMake(0.0, 0.0, 360.0, 480.0);
        widthScreen  = 320.0;
        heightScreen = 490.0;
     //   xScreen      = 150.0;
     //   yScreen      = 190.0;
        UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"LoaderIphone.jpg"]];
        self.view.backgroundColor = background;
        [background release];
   }

    CGRect webFrame = CGRectMake(0.0, 0.0, widthScreen, heightScreen);



    UIWebView *webView= [[UIWebView alloc] initWithFrame:webFrame];
    webView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    webView.scalesPageToFit = NO;
    webView.autoresizesSubviews = YES;

    [webView setBackgroundColor:[UIColor clearColor]];
    //[webView setOpaque:NO];



    //--------- GET THE URL
    NSString *urlAddress= @"";
    urlAddress =[urlAddress stringByAppendingString:resultText.text];
    NSURL *url= [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj= [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];
    [self.view addSubview:webView];
    [webView release];

    // EXAMPLE: do something useful with the barcode image
    resultImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
    //resultImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];


    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    [reader dismissViewControllerAnimated:NO completion:nil];
}

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orient
{
    return(YES);
}


- (void) dealloc {
    self.resultImage = nil;
    self.resultText = nil;
    [super dealloc];
}

@end

if else cgRect 尺寸以前工作得很好,但是我可能不小心删除了一些东西或在某个地方放了一个逗号,这导致了这个错误并导致应用程序在加载时暂停。以下是它返回的错误:

2013-04-03 10:57:35.928 P&H Scanner[269:907] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ReaderSampleViewController 0x21073bc0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key delegate.'
*** First throw call stack:
(0x3346e3e7 0x3b169963 0x3346e0d5 0x33cdc7d9 0x33cd8543 0x333f48a5 0x35419e7d 0x354196ff 0x35312079 0x3529c451 0x352dcd59 0x35327ef7 0xb6cb 0x352ddaa1 0x352dd625 0x352d5833 0x3527dd1f 0x3527d7ad 0x3527d1ef 0x36f955f7 0x36f95227 0x334433e7 0x3344338b 0x3344220f 0x333b523d 0x333b50c9 0x352d446d 0x352d12b9 0xb605 0x3b596b20)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

抱歉,我对应用程序开发相对较新,因此试图解决不同的错误并苦苦挣扎。任何建议都会很棒

4

2 回答 2

3

我学到的一个小技巧是在整个应用程序上设置一个异常断点,因此,每当您遇到无法识别的错误(例如与 UIApplicationMain 相关的错误)时,至少您会大致了解代码中断的位置。这可以给你一个线索,你需要从哪里开始。

为此,您需要转到断点导航器(Cmd+6),按左下角的小加号图标,选择“添加异常断点”,最后按完成。

于 2013-04-03T16:01:53.403 回答
2

让我们看一下日志文件:(“如何读取日志文件:”)

2013-04-03 10:57:35.928 P&H Scanner[269:907] * **由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[ReaderSampleViewController 0x21073bc0 setValue:forUndefinedKey:]:此类不是键值编码-符合关键代表。

因此,您看到终止正在发生,因为您的 ReaderSample 视图控制器声明不正确。要确定究竟是什么不正确,我们可以看一下这部分:

setValue:forUndefinedKey:]:此类不符合键委托的键值编码。

因此,您正在为控制器设置一个值(在您的代码中是 ZBarReaderDelegate),这似乎是导致错误的原因。

因为:这个类不符合键委托的键值编码

希望对您有所帮助,真诚的 Maurice Arikoglu

于 2013-04-03T11:06:08.383 回答