2012-08-08 18 views
0

好吧,所以基本上我是非常新的這一點,一直這樣做大約3天了。我一直在閱讀「傻瓜式iPhone應用程序開發」,並且一直在構建一個教程應用程序。我剛剛添加了代碼來處理視圖滾動時鍵盤出現,但我得到上述錯誤。我知道哪行代碼導致它,但我不知道如何解決它。 下面是一些代碼:可怕的線程1信號SIGABRT在XCODE V4.4與iPhone 5.1模擬

ViewController.h

#import <UIKit/UIKit.h> 

    @interface ViewController : UIViewController 

    @property (retain, nonatomic) IBOutlet UITextField * textField; 


    @property (retain, nonatomic) IBOutlet UILabel *lbl; 


    @end 

ViewController.m

#import "ViewController.h" 

    @interface ViewController() 

    @end 

    @implementation ViewController; 
    @synthesize lbl; 
    @synthesize textField; 

    - (void)viewDidLoad:(BOOL)animated 
    { 
     [super viewDidLoad]; 
    } 
    - (void)viewWillAppear:(BOOL)animated { 

     [[NSNotificationCenter defaultCenter] addObserver: self 
    selector:@selector(keyboardWillShow:) //pretty sure its this line causing issues 
    name:UIKeyboardWillShowNotification 
    object:self.view.window]; 
     [super viewWillAppear:animated]; 

    } 





    -(void)viewWillDisappear:(BOOL)animated { 
     [[NSNotificationCenter defaultCenter] removeObserver:self name:                     UIKeyboardWillShowNotification object: nil]; 
    [super viewWillDisappear:animated]; 
     } 
    // Do any additional setup after loading the view, typically from a nib. 


    - (void)viewDidUnload 
    { 

[self setLbl:nil]; 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
    } 

    - (BOOL)shouldAutorotateToInterfaceOrientation:  (UIInterfaceOrientation)interfaceOrientation 
    { 
     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
      return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
     } else { 
    return YES; 
     } 
    } 

    - (void)dealloc { 
[lbl release]; 
[textField release]; 
[super dealloc]; 
    } 
    @end 

在調試控制檯的錯誤消息是

2012-08-08 10:48:56.873 tester[552:c07] -[ViewController keyboardWillShow:]:   unrecognized selector sent to instance 0x6a5f6b0 
    2012-08-08 10:48:56.875 tester[552:c07] *** Terminating app due to uncaught exception   'NSInvalidArgumentException', reason: '-[ViewController keyboardWillShow:]: unrecognized   selector sent to instance 0x6a5f6b0' 
    *** First throw call stack: 
    (0x14b2022 0xeb2cd6 0x14b3cbd 0x1418ed0 0x1418cb2 0x9d7a29 0x147d855 0x147d778 0x91c19a 0x3ab4cb 0x3a6906 0x3a851f 0x3a85a9 0x3a85f3 0x3a2938 0x103678 0x10312e 0x2e28fb 0x2e45f8 0x2dce29 0x2dc133 0x2dd3bf 0x2dfa21 0x2df97c 0x2d83d7 0x3d1a2 0x3d532 0x23dc4 0x17634 0x139cef5 0x1486195 0x13eaff2 0x13e98da 0x13e8d84 0x13e8c9b 0x139b7d8 0x139b88a 0x15626 0x26b2 0x2625) 
    terminate called throwing an exception(lldb) 

誰能幫助我?

回答

3

你沒有一個叫keyboardWillShow:的方法,所以有點像給朋友一個不存在的地址,當他無法找到它(並且崩潰)時他發脾氣。

要解決這個問題,只需添加類似的東西;

- (void)keyboardWillShow:(id)sender { }

+0

那會進入.m或.h嗎? – Craig 2012-08-08 10:33:29

+0

在.m文件中 - .h用於聲明公共變量和方法,而.m是將所有邏輯寫入類的位置,以及私有變量和方法。 – 2012-08-08 10:35:23

+0

感謝編輯@ jrturton - 忘記添加發件人引用,這會引發另一個異常;) – 2012-08-08 10:37:18