“NSInvalidArgumentException” UIButton IBAction 错误
我的视图中有一个按钮无法工作。我已经在 X-Code 的空白默认视图应用程序中工作,但在我的任何应用程序中它都不起作用,而是给了我以下错误。
由于未捕获而终止应用程序 例外 'NSInvalidArgumentException',原因: '*** -[UIViewController showVicInfo:]: 无法识别的选择器发送到实例 0x3c084f0'
调试器也没有任何帮助。我已确保将按钮也连接到文件的所有者(而不是相反)。以下是该操作的代码。我知道这不是警报视图,因为断点甚至没有到达那里。
about.h
@interface about : UIViewController {
}
-(IBAction)showVicInfo:(id)sender;
about.m
-(IBAction)showVicInfo:(id)sender {
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"You require an internet connection via WiFi or cellular network for iFirelert to work." delegate:self cancelButtonTitle:@"OK, thanks" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
}
更新:仅供参考,这就是我创建按钮的方式(如果有帮助的话)。
- 创建了新视图(文件>新文件>UIViewControllerSubclass w/XIB接口)
- 添加-(IBAction)showInfo:(id)sender;到 about.h
- 添加
- -(IBAction)showVicInfo:(id)sender { UIAlertView *myAlert = [[UIAlertView 分配] initWithTitle:@"没有互联网 连接”消息:@“您需要一个 通过 WiFi 连接互联网或 iFirelert 的蜂窝网络 工作。”代表:自己 cancelButtonTitle:@“好的,谢谢” 其他按钮标题:nil]; [我的警报显示]; [我的警报发布]; 在 Interface Builder 中打开About.xib
- ,将一个矩形按钮拖到视图上
- 通过按住 Ctrl 键并单击按钮到文件的 Owner 属性(而不是相反),将该按钮连接到 -showVicInfo 操作。
- 检查文件的所有者是否设置为“about”类。
然后在 X-Code 中构建并运行失败。
更新 2:好的,我已经弄清楚它一定是我现有项目中的一个设置或某些东西。我已经复制了两个类文件和 XIB 文件,它们在另一个 X-Code 项目中工作,但按钮也会抛出相同的错误现有应用程序中的错误。
I have a button in a view which refuses to work. I've got in working in a blank, default view application from X-Code, but in none of my applications will it work, instead it gives me the following error.
Terminating app due to uncaught
exception
'NSInvalidArgumentException', reason:
'*** -[UIViewController showVicInfo:]:
unrecognized selector sent to instance
0x3c084f0'
The debugger isn't any help either. I've made sure that I hook up the button to the file's owner (not the other way around) as well. Below is the code for the action. And I know it's not the alert view, because the breakpoint doesn't even reach there.
about.h
@interface about : UIViewController {
}
-(IBAction)showVicInfo:(id)sender;
about.m
-(IBAction)showVicInfo:(id)sender {
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"You require an internet connection via WiFi or cellular network for iFirelert to work." delegate:self cancelButtonTitle:@"OK, thanks" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
}
Update: FYI this is how I went about creating the button,if it helps.
- Created new view (File>New File>UIViewControllerSubclass w/XIB for interface)
- Added -(IBAction)showInfo:(id)sender; to about.h
- Added
- -(IBAction)showVicInfo:(id)sender {
UIAlertView *myAlert = [[UIAlertView alloc]
initWithTitle:@"No Internet
Connection" message:@"You require an
internet connection via WiFi or
cellular network for iFirelert to
work." delegate:self
cancelButtonTitle:@"OK, thanks"
otherButtonTitles:nil];
[myAlert show];
[myAlert release];
} to about.m - Opened About.xib in Interface Builder, dragged a Rectangular Button onto the View
- Hooked up the button to the -showVicInfo action by ctrl-clicking the button to the File's Owner property (not the other way around).
- Checked the File's Owner was set to "about" class which it is.
And then built and run with failure in X-Code.
Update 2: OK, I've worked out it must be a setting or something in my existing project.I've copied the two class files and XIB file which does work in another X-Code project, but the button also throws the same error in the existing app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有同样的错误。问题是我释放了viewController。
如果你不释放一切都很好
Had the same error. The problem was that I released the viewController.
Everything is fine if you don't release it
我认为 Squeegy 是对的,你的 VC 是一个普通的旧 UIViewController 并且不接受 showVicInfo。
您是否在 IB 中为 ViewController 设置了类(command-4)?
或者,如果您自己分配它,您是否这样做:
当您应该这样做时:
错误消息告诉您 showVicInfo 正在发送到 0x3c084f0。检查您创建的视图控制器的地址(如上面“vc”中的值),如果它是 0x3c084f0,那就是您的答案。当然,下次该值可能会有所不同,但是在创建它时对其进行 NSLog,然后将其与错误消息进行比较,以确定它所指的内容。
还要检查 IB 中的按钮是否正确连接。如果您选择该按钮并转到“按钮连接”选项卡,您应该有连接。对于 Touch Up Inside 应该连接到您的操作函数,在您的 IB 中它应该连接到 showVicInfo:
I think Squeegy is right, your VC is a plain old UIViewController and doesn't accept showVicInfo.
Did you set the class (command-4) for your ViewController in IB?
Or if you are allocating it yourself, are you doing it like this:
when you should be doing this:
The error message is telling you that showVicInfo was being sent to 0x3c084f0. Check the address of the view controller that you created (like the value in "vc" above), if it's 0x3c084f0 that's your answer. Of course the value may be different next time, but NSLog it when you create it and then compare it to the error message to know for sure what it is referring to.
Check also that you have the button hooked up correctly in IB. If you select the button and go to the Button Connections tab you should have connections. For Touch Up Inside should connect to your action function, in your IB it should connect to showVicInfo: