Objective-C exception thrown. Name: NSInvalidArgumentException

I have a basic say hello button on a tabbed layout in the third view (in total I have 3 virecontrollers:FirstViewController, SecondViewController,ThirdViewController). In the third I put a button anf from xcode ui builder I have defined outlet and action for the button (action: sayhello)
When I click the button if I have created the button delegate action or not I have the same error:
Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[ThirdViewController sayhello:]: unrecognized selector sent to instance 0xc1daff0
Where do I'm wrong ?
THanks in advance for the hint.
Max

Posts

  • adamkempadamkemp USInsider, Developer Group Leader mod

    You may have a stale/invalid connection in a .xib file. Delete that or provide an appropriate method in ThirdViewController to handle that action:

    [Export("sayhello:")]
    private void SayHello(NSObject sender)
    {
    }
    
  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭
    edited February 2014
    [Register ("ThirdViewController")]
        partial class ThirdViewController
        {
            [Outlet]
            MonoTouch.UIKit.UIButton gobutton { get; set; }
    
            [Action ("sayhello:")]
            partial void sayhello (MonoTouch.Foundation.NSObject sender);
    
            void ReleaseDesignerOutlets ()
            {
                if (gobutton != null) {
                    gobutton.Dispose ();
                    gobutton = null;
                }
            }
        }
    

    I have folowed guidelines, but I don't see any addictional code for the controller (above my designer contents)

  • MassimilianoFabbriMassimilianoFabbri USMember ✭✭
    edited February 2014

    I have adde your code to the controller, now
    the issue is here:
    Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[ThirdViewController start:]: unrecognized selector sent to instance 0x12e24470

    'start' is an object (uibutton) I deleted but It is still present somewhere..... how do I can fix it ?

  • I solved. I found in xcode ui builder every action you define for an outlet still remains in object properties but It is not visible into designer. I've done right click on the uibutton in the view and from contextual menu I see there was still an action 'start' defined previously and deleted by hand in the designer. Deleting from the object contextual menu It fixed.
    What I dont understand is why to add also this code to have a working app:

    [Export("sayhello:")]
    private void SayHello(NSObject sender)
    {
    }
    
  • HoangPhuongHoangPhuong USMember

    In the event of my button accidentally created UpInside. I just delete it then works fine. Thanks Andres Ramirez

  • ShriGuru_BaskarShriGuru_Baskar USMember
    edited June 2017

    This issue could occur

    1. when the designer.cs file has an "touchup_inside" method declared , and the implementing
      method in the viewcontroller class has a different signature of the method or the method name has some casing mismatch.
    2. When there is already an event wired up in designer.cs file and there is another ambiguous touchup inside event added in viewcontroller UIbutton events. And the objective -c cannot identify which event to be fired
Sign In or Register to comment.