8
votes

I have been following the "Hello, iPhone" tutorial available in xamarin website. I have completed all the steps now. Now, I run the application and click on the "Action 1" button I am getting this error

Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[HelloWorld_iPhoneViewController actionButtonClick:]: unrecognized selector sent to instance 0xb3a5a30 enter image description here How can I fix this issue ? I am using the latest versions of 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
    }

my code uploaded to here

3

3 Answers

9
votes

If you look at the connections for the button (in Xcode) you'll see that you've added 2 actions to the button - one called actionButtonClick and one called actnButtonClick.

In the controller, MonoTouch appears to have only added a partial method for the second action which isn't the one that is crashing.

I deleted the action called actionButtonClick (leaving actnButtonClick) and ran your sample which ran fine.

6
votes

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.

0
votes

Just open the storyboard file with the source code editor and remove any connection that you don't want listed under the button.

<button ...>
  .
  .
  .

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

</button>