2011-06-09 101 views
16

我正在嘗試使用Interface Builder編譯和運行Objective C應用程序的簡單教程。我使用的Xcode 4.0.2和iOS模擬(iPhone)4.3Objective C,線程1程序接收信號SIGABRT

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 ...線程1:編程接收信號「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 2011-06-09 14:19:11

+0

這夠了嗎?這幾乎是一切。 – 2011-06-09 15:30:58

+0

是的!這應該足以給你一個答案,我現在正在解析它。 – jv42 2011-06-09 15:45:09

回答

21

您的NIB/XIB文件中有錯誤。

它看起來像你以前連接了一個IBOutlet(textInput),現在連接已斷開。您應該再次檢查Interface Builder中的所有連接。

2

現在我明白了!您的崩潰報告說:

Unknown class InterfaceBuilderAppDelegate_iPhone 

所以,似乎你設置應用程序委託在IB這一類,但這個類是不具備的項目。檢查這個。要麼拼錯類名,要麼將相關類添加到項目中。

極有可能,您的文本字段已連接到此應用程序委託。

您是否已將Interface Builder中的文本字段連接到SimpleUIViewController插座?

由於從教程中可以看出您沒有使用MainWindow.xib,所以我會說您的項目缺少運行正確的代理。嘗試在你的主要進行此更改:

int retVal = UIApplicationMain(argc,argv,nil,@「SimpleUIAppDelegate」);

如果我的假設是正確的,那就應該推動你的前進。

+0

那沒有做到。我仍然在相同的地方得到相同的錯誤信息。但是,究竟做了什麼? – 2011-06-09 15:27:10

+0

而我正在使用MainWindow.xib – 2011-06-09 15:27:57

+0

請參閱我的編輯,請... – sergio 2011-06-09 15:35:54

3

這很可能是您的'File's Owner'錯誤地設置到您的SimpleUIViewController的xib中的UIViewController。請在身份檢查器窗格中將其設置爲SimpleUIViewController。

0

線程1個程序recived葛SIGABRT

有時NSString的值去nill!

它可能會導致此應用程序的初始化!

2

要解決該問題,請在Interface Builder中加載XIB,選擇文件檢查器選項卡,然後取消選中使用自動佈局。或者,如果您絕對必須具有自動佈局功能,則可以僅限iOS 6.0 +設備並更改最低目標。

NSLayoutConstraint SIGABRT on iPad

相關問題