Objective C,线程1程序接收到信号SIGABRT

16
我正在尝试使用Interface Builder编译和运行一个Objective C应用的简单教程。我正在使用Xcode 4.0.2,并在iOS(iPhone)4.3上进行模拟。

http://www.switchonthecode.com/tutorials/creating-your-first-iphone-application-with-interface-builder

当我构建项目时,它能够正常构建,但一旦应用程序尝试运行,就会崩溃并显示以下错误信息:

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

我在第4行遇到了错误:int retVal = UI... Thread 1: Program Received Signal "SIGABRT"。

如果这个项目的其他文件需要上传以便更清晰地理解,我可以做到。

谢谢!

编辑:

SimpleUIViewController.h:

#import <UIKit/UIKit.h>

@interface SimpleUIViewController : UIViewController <UITextFieldDelegate> {
    UITextField *textInput;
    UILabel *label;
    NSString *name;
}

@property (nonatomic, retain) IBOutlet UITextField *textInput;
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, copy) NSString *name;

- (IBAction)changeGreeting:(id)sender;

@end

SimpleUIViewController.m:

#import "SimpleUIViewController.h"

@implementation SimpleUIViewController

@synthesize textInput;
@synthesize label;
@synthesize name;

- (IBAction)changeGreeting:(id)sender {
    self.name = textInput.text;

    NSString *nameString = name;
    if([nameString length] == 0) {
        nameString = @"Inigo Montoya";
    }
    NSString *greeting = [[NSString alloc] 
                          initWithFormat:@"Hello, my name is %@!", nameString];
    label.text = greeting;
    [greeting release];
}

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    if(theTextField == textInput) {
        [textInput resignFirstResponder];
    }
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; 
    // Release anything that's not essential, such as cached data
}

- (void)dealloc {
    [textInput release];
    [label release];
    [name release];
    [super dealloc];
}

@end

错误信息:
This GDB was configured as "x86_64-apple-darwin".Attaching to process 2668.
2011-06-09 11:20:21.662 InterfaceBuilder[2668:207] Unknown class InterfaceBuilderAppDelegate_iPhone in Interface Builder file.
2011-06-09 11:20:21.666 InterfaceBuilder[2668:207] *** Terminating app due to uncaught     exception 'NSUnknownKeyException', reason: '[<UIApplication 0x4b1a900>     setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key  textInput.'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00dc25a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x00f16313 objc_exception_throw + 44
    2   CoreFoundation                      0x00dc24e1 -[NSException raise] + 17
    3   Foundation                          0x00794677 _NSSetUsingKeyValueSetter + 135
    4   Foundation                          0x007945e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
    5   UIKit                               0x0021030c -[UIRuntimeOutletConnection connect] + 112
    6   CoreFoundation                      0x00d388cf -[NSArray makeObjectsPerformSelector:] + 239
    7   UIKit                               0x0020ed23 -[UINib instantiateWithOwner:options:] + 1041
    8   UIKit                               0x00210ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
    9   UIKit                               0x0001617a -[UIApplication _loadMainNibFile] + 172
    10  UIKit                               0x00016cf4 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 291
    11  UIKit                               0x00021617 -[UIApplication handleEvent:withNewEvent:] + 1533
    12  UIKit                               0x00019abf -[UIApplication sendEvent:] + 71
    13  UIKit                               0x0001ef2e _UIApplicationHandleEvent + 7576
    14  GraphicsServices                    0x00ffb992 PurpleEventCallback + 1550
    15  CoreFoundation                      0x00da3944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    16  CoreFoundation                      0x00d03cf7 __CFRunLoopDoSource1 + 215
    17  CoreFoundation                      0x00d00f83 __CFRunLoopRun + 979
    18  CoreFoundation                      0x00d00840 CFRunLoopRunSpecific + 208
    19  CoreFoundation                      0x00d00761 CFRunLoopRunInMode + 97
    20  UIKit                               0x000167d2 -[UIApplication _run] + 623
    21  UIKit                               0x00022c93 UIApplicationMain + 1160
    22  InterfaceBuilder                    0x000027ff main + 127
    23  InterfaceBuilder                    0x00002775 start + 53
    24  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
sharedlibrary apply-load-rules all
Current language:  auto; currently objective-c
(gdb) 

我是obj-c的新手,对于那个错误信息完全不知所措。有人能帮忙吗?


1
是的,我认为你需要提供更多的代码和崩溃信息... 除了 SIGABRT,你还有其他的异常、调用堆栈等吗? - jv42
够了吗?这几乎是所有的东西。 - eric.mitchell
是的!这应该足以给你一个答案,我正在解析它。 - jv42
5个回答

21

您的 NIB/XIB 文件出现了错误。

看起来您之前已经连接过一个 IBOutlet (textInput),但现在连接已经断开。您应该仔细检查 Interface Builder 中所有的连接。


3

很可能你在SimpleUIViewController的xib文件中,将“文件所有者(File's Owner)”的类型错误地设置为了UIViewController。请在身份检查器面板中将其设置为SimpleUIViewController。


2
为了解决这个问题,可以在Interface Builder中加载XIB文件,选择File Inspector选项卡,然后取消勾选“使用自动布局”选项。或者,如果你一定要使用自动布局,可以将最低目标设为iOS 6.0+版本的设备。详情请参考此处

2
现在我明白了!你的崩溃报告显示:
Unknown class InterfaceBuilderAppDelegate_iPhone

所以,看起来你在IB中将你的App Delegate设置为这个类,但是这个类在你的项目中不可用。请检查一下,你可能拼错了类名,或者你应该将相关类添加到你的项目中。
很有可能,你的文本字段连接到了这个应用程序委托。 你是否在Interface Builder中将你的文本字段连接到SimpleUIViewController输出口? 由于从教程中看来,你没有使用MainWindow.xib,我会说你的项目缺少运行正确的代理。尝试在你的主要代码中进行以下更改: int retVal = UIApplicationMain(argc, argv, nil, @"SimpleUIAppDelegate"); 如果我的假设是正确的,那么这应该可以帮助你前进。

那没起作用。我在同样的地方仍然收到相同的错误信息。不过,那到底做了什么? - eric.mitchell
我正在使用MainWindow.xib。 - eric.mitchell
我想是这样的...?嗯,那就是通过控制点击并添加一个动作完成的,对吧?如果是这样的话,那就是了。 - eric.mitchell

0

线程1程序收到信号sigabrt

有时NSString的值会变成nil!

这可能是在初始化应用程序时引起的!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接