iOS,无法识别的选择器发送到实例?
我有一个带有导入自定义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] *终止应用程序由于未捕获的exception’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类型的未捕获exception终止
有谁能告诉我为什么? 最重要的是能够帮我解决这个问题^^?
您正在释放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]; //... }
希望有所帮助!