8

我一直在关注 xamarin 网站上提供的“ Hello, iPhone ”教程。我现在已经完成了所有的步骤。现在,我运行应用程序并单击“操作 1”按钮我收到此错误

抛出 Objective-C 异常。名称:NSInvalidArgumentException 原因:-[HelloWorld_iPhoneViewController actionButtonClick:]:无法识别的选择器发送到实例 0xb3a5a30 在此处输入图像描述 我该如何解决这个问题?我正在使用最新版本的 MonoDevelop + MonoTouch

static void Main (string[] args)
    {
        // if you want to use a different Application Delegate class from "AppDelegate"
        // you can specify it here.
        UIApplication.Main (args, null, "AppDelegate"); <-- HERE
    }

我的代码上传到这里

4

3 回答 3

9

如果您查看按钮的连接(在 Xcode 中),您会看到您已向按钮添加了 2 个操作 - 一个称为 actionButtonClick,另一个称为 actnButtonClick。

在控制器中,MonoTouch 似乎只为第二个动作添加了一个部分方法,这不是崩溃的那个。

我删除了名为 actionButtonClick 的操作(离开 actnButtonClick)并运行了运行良好的示例。

于 2013-02-16T22:14:24.623 回答
6

In the "Xamarin Cross-platform Application Development" book by Jonathan Peppers I ran into the same "very newby" problem with his "Hello Phone" example.

This is what I did to fix it.

First, I switched into Xamarin Studio, clicked on the MainStoryboard.storyboard file or tab (to show the phone layout), clicked on the "button" within the layout, to display its "Properties" in the lower right window.

Then I selected "Events" within the "Properties" window (from the buttons showing "Widget", "Layout", "Events".

Lastly, under the item called "Up Inside" there was a small "x" available to delete the event handler that was listed there -- which I recall was named button_TouchUpInside (or something like that).

The example code (page 25 of the book) is adding an event handler for the button, so this other handler is an extra (unwritten?) one, and removing reference to it made the example work fine.

于 2014-06-18T16:47:44.703 回答
0

只需使用源代码编辑器打开故事板文件,然后删除您不想在按钮下列出的任何连接。

<button ...>
  .
  .
  .

   <connections>
         <!-- remove any connections here that you don't want -->             
   </connections>

</button>
于 2015-03-09T08:23:55.300 回答