2013-07-15 75 views
0

我最近開始研究基本的IOS應用程序開發我正在使用以下教程在線https://www.youtube.com/watch?v=GHK3oREwVls&list=PLhAWmh1PlbzGrr8PGLvJBtJ7qniLVTQ9E,我似乎碰到了一個絆腳石,下面是我的兩個視圖控制器。我得到的錯誤是關於視圖控制器M的displaytext.text部分。出現的錯誤是;Hello World Objective-C問題

HelloCocoaViewController.m:30:4:使用未聲明的標識符'displaytext';你的意思是'_displaytext'?

當我進行建議的更改時,我得到圍繞下面的代碼的線程1:信號SIGABRT。

@autoreleasepool { 
     return UIApplicationMain(argc, argv, nil, NSStringFromClass([HelloCocoaAppDelegate class])); 

下面是我目前使用的代碼。

// 
// HelloCocoaViewController.h 
// Test 
// 

#import <UIKit/UIKit.h> 

@interface HelloCocoaViewController : UIViewController 
@property (weak, nonatomic) IBOutlet UILabel *displaytext; 
- (IBAction)hellobutton:(id)sender; 
- (IBAction)byebutton:(id)sender; 

@end 


// 
// HelloCocoaViewController.m 
// Test 
// 
// 

#import "HelloCocoaViewController.h" 

@interface HelloCocoaViewController() 

@end 

@implementation HelloCocoaViewController 

- (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. 
} 

- (IBAction)hellobutton:(id)sender { 
    [email protected]"Hello"; 

} 

- (IBAction)byebutton:(id)sender { 
    [email protected]"Bye"; 
} 
@end 

我會很感激任何和所有的幫助。

編輯:我現在試圖實現建議的解決方案(我希望這是正確的),但我是基石經歷同樣的SIGABRT問題。

@implementation HelloCocoaViewController 
@synthesize displaytext; 

- (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. 
} 

- (IBAction)hellobutton:(id)sender { 
    [email protected]"Hello"; 

} 

- (IBAction)byebutton:(id)sender { 
    [email protected]"Bye"; 
} 
@end 
+0

據我知道SIGABRT錯誤總是會告訴你,你的應用程序的主要部分,這是一個普遍錯誤,但您可以在xcode左側看到該錯誤之前基本上發生了什麼。我想說,你需要綜合你的uilabel屬性,但另一個用戶抓住它,所以我給他們一個upvote。基本上你需要一個@synthesize顯示文本;在你的類的.m文件中執行helloCocoaViewController,以及在你的代碼中將displaytext.text改爲self.displaytext.text ...你將會學習到你爲什麼進行學習,基本上看不見的方法。 – rezand

+0

瞭解調試的細節很重要。首先,您需要學習如何設置一般的斷點以及如何理解控制檯日誌和調試數據顯示。然後你需要設置一個異常斷點,這樣大多數錯誤都會以一種允許你在錯誤時檢查調用堆棧的方式被捕獲。 –

+0

檢查[this](http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1),找出您的應用崩潰的原因。或者只是查看教程,找出你不明白的以及你做錯了什麼(如果應用程序在教程中有效)。 – CaptJak

回答

2

因爲你不使用@synthesize定義屬性的一個後盾變量會隱式添加作爲_<propertyname>

所以無論是使用屬性爲self.displaytext或通過_displaytext

直接訪問屬性的後盾變量

由於Apple將默認編譯器從GCC切換到了llvm,Objective-C發展非常快。 WWDC影片,以保持這些改進