0

因此,将以下代码段添加到我的源代码后,应用程序拒绝运行并给我一个 SIGABRT 错误:

CIALBrowserViewController.h

UIBarButtonItem *homeButtonItem;

CIALBrowserViewController.m

@interface CIALBrowserViewController ()
- (void)goHome:(id)sender;

..

homeButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"home.png"]
                                                          style:UIBarButtonItemStylePlain
                                                         target:self
                                                         action:@selector(goHome:)] autorelease];

..

- (void)goHome:(id)sender {
NSURL *url = [NSURL URLWithString:@"http://google.ca/"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}

SIGABRT 错误

2012-06-17 14:15:15.130 CIALBrowser[1753:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x354fa88f 0x378a1259 0x3544f1d7 0x5f8b 0x32f67c17 0x2a67 0x32f66cab 0x32f607dd 0x32f2eac3 0x32f2e567 0x32f2df3b 0x370ed22b 0x354ce523 0x354ce4c5 0x354cd313 0x354504a5 0x3545036d 0x32f5f86b 0x32f5ccd5 0x28df 0x2878)
terminate called throwing an exception(lldb)

以下是 CIALBrowserViewController.m 的完整源代码:http: //pastebin.com/uuUgi7Dc

4

2 回答 2

0

SIGABRT 错误表明您在代码中的某处使用该方法insertObject:atIndex:并将nil其用作第一个参数,这是不允许的,会引发错误。我在 paste bin 上查看了您的代码,但没有看到那里调用了该方法,因此错误可能在另一个文件中。

希望这可以帮助!

于 2012-06-17T18:37:16.730 回答
0

else的部分中if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad),没有homeButtonItem分配或初始化,所以homeButtonItem也是 nil。然后[buttons addObject:homeButtonItem];会崩溃,因为您正在向数组添加一个 nil 对象。

于 2012-06-18T03:08:36.270 回答