簡體   English   中英

iOS,無法識別的選擇器發送到實例?

[英]iOS, unrecognized selector sent to instance?

我有一個帶有導入自定義actionBar的主屏幕。 我在一個單獨的.xib文件中創建了這個actionBar,其中包含.m和.h文件。

我在actionBar.m的viewDidLoad做了一些圖形設置,比如backgroundColor和其他一些東西。

我在這個actionBar上也有一個按鈕,我通常用IBAction鏈接按鈕的方式。

我將actionBar加載到我的主屏幕中,如下所示:

ActionBarWithLogoff *actionBar = [[ActionBarWithLogoff alloc] initWithNibName:@"ActionBarWithLogoff" bundle:nil];
[topBar addSubview:actionBar.view];
[actionBar release];

我的actionBar.h:

- (IBAction)ActionBarLogoff:(id)sender;

我的actionBars.m的方法:

-(void) ActionBarLogoff:(UIButton *)sender
{
NSLog(@"!!!!!!!!!!ActionBarLogoff");
}

這是我的錯誤鋼鐵圖片,當我點擊按鈕我得到以下錯誤:

2014-01-27 13:52:21.856 GB_Mobil_DK [2954:60b] - [__ NSArrayM ActionBarLogoff:]:無法識別的選擇器發送到實例0x1656d880 2014-01-27 13:52:21.858 GB_Mobil_DK [2954:60b] *終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因是: ' - [__ NSArrayM ActionBarLogoff:]:無法識別的選擇發送到實例0x1656d880' *第一擲調用堆棧:(0x2f94be83 0x39ca86c7 0x2f94f7b7 0x2f94e0af 0x2f89cdc8 0x32104da3 0x32104d3f 0x32104d13 0x320f0743 0x3210475b 0x32104425 0x320ff451 0x320d4d79 0x320d3569 0x2f916f1f 0x2f9163e7 0x2f914bd7 0x2f87f471 0x2f87f253 0x345b92eb 0x32134845 0x97985 0x3a1a1ab7)libc ++ abi.dylib:以NSException類型的未捕獲異常終止

有誰能告訴我為什么? 最重要的是能夠幫我解決這個問題^^?

您正在釋放actionBar實例並保留其view 如果actionBar實例響應按鈕操作,則按鈕單擊消息將被發送到已刪除的實例。 您應該保留actionBar實例。 一種方法是將其作為ivar或retain財產。

看起來您正在為自定義視圖創建UIViewController 相反,您可以使用其XIB創建自定義UIView

編輯

聲明保留財產,

@property (nonatomic, retain) ActionBarWithLogoff *actionBar;

要么

簡單地聲明為ivar,

@interface YourViewController: UIViewController {
    ActionBarWithLogoff *actionBar;
}

dealloc方法中,

-(void) dealloc {
    //...

    [actionBar release];

    //...
}

希望有所幫助!

暫無
暫無

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

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