从 xib 内的按钮单击调用 IBAction 时出现错误

发布于 2024-09-08 22:02:56 字数 528 浏览 0 评论 0原文

我遇到一个问题,当我从某个视图控制器调用 IBaction 时,应用程序崩溃,但我可以在其他地方获得所需的结果。

基本上我有一个隐藏在标签栏控制器中的导航控制器。如果我从导航控制器的第一个视图调用 IBActions 它工作正常,但如果我使用 initWithNib 创建一个视图并将其推送到导航控制器堆栈,然后尝试在我推送的视图控制器实例上调用 IBAction堆栈应用程序崩溃。

当应用程序首次加载时,菜单栏中有一个“x”按钮,可以拉出地址簿选择器。这很好用。如果您单击菜单栏中的“新建”按钮,则会创建适当的视图并将其推送到堆栈上。这个新视图有 1 个名为“选择账单到”的按钮,该按钮在 IBAction 调用中只有一条日志语句,但仍然会导致崩溃。 “选择帐单收件人”按钮的 IBAction 位于该视图视图控制器中。

任何帮助解决这个问题的帮助将不胜感激。

源代码可以在 http://www.swnsn.com/S4X.zip 找到

i am having an issue where when i call an IBaction from a certain viewcontroller the app crashes, but i can get the desired result elsewhere.

basically i have a navigationcontroller buried in a tab bar controller. if i call an IBActions from the first view of the navigationcontroller it works fine, but if i create a view with an initWithNib and push it on to the navcontroller stack and then try to call an IBAction on the instance of the viewcontroller i pushed on the stack the app crashes.

when the app first loads there is an "x" button in the menubar which pulls up an addressbook picker. this works fine. if you click on the "new" button in the menubar the propper view gets created and pushed on the stack. this new view has 1 button called "sellect bill to" which only has a log statement in the IBAction call but still causes a crash. the IBAction for the "select bill to" button is location in that views viewcontroller.

any help untangling this would be appreciated.

source can be found at http://www.swnsn.com/S4X.zip

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

所谓喜欢 2024-09-15 22:02:56

您尝试将 pickBillTo: 发送到 UIViewController 的实例,而不是您的自定义子类。

在 FirstViewController.m 中,将: 更改

UIViewController *newView = [[UIViewController alloc] initWithNibName:@"NewOrderView" bundle:nil];

为:

NewOrderView *newView = [[NewOrderView alloc] initWithNibName:@"NewOrderView" bundle:nil];

您还必须导入 NewOrderView.h,并且您可能应该将该类重命名为 NewOrderViewController,并将变量命名为 newViewController,因为它是控制器,而不是视图。

You're trying to send pickBillTo: to an instance of UIViewController, not your custom subclass.

In FirstViewController.m, change:

UIViewController *newView = [[UIViewController alloc] initWithNibName:@"NewOrderView" bundle:nil];

to:

NewOrderView *newView = [[NewOrderView alloc] initWithNibName:@"NewOrderView" bundle:nil];

You'll also have to import NewOrderView.h, and you should probably rename that class to NewOrderViewController, and name your variable newViewController, since it's a controller, not a view.

长安忆 2024-09-15 22:02:56

我只是一个初学者。所以我的建议可能不正确。

A.

我检查了调试器控制台,出现以下错误
'NSInvalidArgumentException',原因:'*** -[UIViewController pickBillTo:]:无法识别的选择器发送到实例 0x44487f0'
我不确定问题是什么。

B.C.

-(IBAction)pickBillTo:(id) selector{ // Your code
-(IBAction)pickBillTo:(id) sender{ // my suggestion

内存

你还没有释放
按钮、名字、姓氏、数字

I am just a beginner. So i might not be right in my suggestions.

A.

I checked the Debugger console and the following error is
'NSInvalidArgumentException', reason: '*** -[UIViewController pickBillTo:]: unrecognized selector sent to instance 0x44487f0'
I m not sure what the problem is.

B.

-(IBAction)pickBillTo:(id) selector{ // Your code
-(IBAction)pickBillTo:(id) sender{ // my suggestion

C.

You haven't released memory for
button, firstName, lastName, number

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文