簡體   English   中英

為什么在我的應用程序中看到以下異常?

[英]Why am I seeing the following exception within my application?

我正在創建一個iPhone應用程序。 我有兩個視圖控制器(主要的一個和一個關於窗口)。 在About視圖控制器中,我有一個UIButton,它鏈接到視圖控制器中的IBAction。

我越來越:

2010-08-05 21:40:05.741 appname[9151:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[aboutViewController gotoMain2]: unrecognized selector sent to instance 0x5c09950'

這是代碼:

//
//  aboutAboutViewController.h
//
//  Created by **** on 5/08/10.
//  Copyright 2010 ***. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface AboutViewController : UIViewController {

}
- (IBAction)gotoMain2;
@end

And the .m file:

//
//  AboutViewController.m
//
//  Created by **** on 5/08/10.
//  Copyright 2010 ****. All rights reserved.
//

#import "AboutViewController.h"

@implementation AboutViewController
- (IBAction)gotoMain2 { 
 [self dismissModalViewControllerAnimated:TRUE];
}
@end

我100%確保在xCode和Interface Builder中所有內容都正確鏈接

任何幫助是極大的贊賞

謝謝。 丹尼爾

更新:我剛剛發現它試圖指向一個不同的類。但是在IB中它是正確的???

您應該檢查在哪里實際創建AboutViewController實例。 設置“文件所有者”的類只是告訴IB 期望什么類。 但是可能加載此筆尖的實際對象不是AboutViewController。

順便說一句,“編輯”錯誤消息以隱藏一些秘密是掩蓋實際錯誤並使其他人更難以幫助的好方法。 :)

該錯誤消息顯示aboutViewController ,但是在您的代碼中它名為AboutViewController 確保大小寫匹配,同樣在Interface Builder屬性中。

如果安裝正確,則為“ Thing Inside(TM)”。

刪除按鈕。 創建一個新的,然后重新設置。

確保退出並在Interface Builder中重新加載。

嘗試:

- (IBAction)goToMain2:(id)sender;

- (IBAction)goToMain2:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}

顯然,您沒有將其正確鏈接,否則您將不會獲得異常。

我不介意打賭錯誤消息看起來更像這樣:

-[AboutViewController gotoMain2:]: unrecognized selector sent to instance 0x5c09950
                               ^^ colon here

我認為的原因是通常這樣聲明IBAction

-(IBAction) doAnAction: (id) sender;
                      ^^^^^^^^^^^^^ actions take a parameter which is the object that sends them..

如果這不是問題,則需要在調試器中運行帶有異常中斷的應用程序。 然后,您可以檢查將動作發送到的對象是否確實是您認為的樣子。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM