NSInvalidArgumentException, unrecognized selector sent to instance 0x101b3c3c0

ranju_ranju_ Member ✭✭
edited January 11 in Xamarin.iOS

I am trying to call async method from button click event like below:
public override void ViewDidLoad()
{
base.ViewDidLoad();
btnSaveRecord.TouchUpInside += async (Object sender, EventArgs e) =>
{
await RegisterUserAsync();
};

        }

But getting the below exception:

    Unhandled Exception:

    Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[SqlDBController BtnSaveRecord_TouchUpInside:]: unrecognized selector sent to instance 0x101b3c3c0
    Native stack trace:
        0   CoreFoundation                      0x000000018a318edc <redacted> + 252
        1   libobjc.A.dylib                     0x00000001894e9a40 objc_exception_throw + 56
        2   CoreFoundation                      0x000000018a231c24 <redacted> + 0
        3   UIKitCore                           0x00000001b721ccd8 <redacted> + 280
        4   CoreFoundation                      0x000000018a31e7dc <redacted> + 1412
        5   CoreFoundation                      0x000000018a32048c _CF_forwarding_prep_0 + 92
        6   UIKitCore                           0x00000001b71f0bd4 <redacted> + 96
        7   UIKitCore                           0x00000001b6c7e48c <redacted> + 80
        8   UIKitCore                           0x00000001b6c7e7ac <redacted> + 440
        9   UIKitCore                           0x00000001b6c7d7ac <redacted> + 568
        10  UIKitCore                           0x00000001b722a32c <redacted> + 2472
        11  UIKitCore                           0x00000001b722b590 <redacted> + 3156
        12  UIKitCore                           0x00000001b720a88c <redacted> + 340
        13  UIKitCore                           0x00000001b72d90f8 <redacted> + 1620
        14  UIKitCore                           0x00000001b72dbaf0 <redacted> + 4740
        15  UIKitCore                           0x00000001b72d45e0 <redacted> + 152
        16  CoreFoundation                      0x000000018a2a91f0 <redacted> + 24
        17  CoreFoundation                      0x000000018a2a9170 <redacted> + 88
        18  CoreFoundation                      0x000000018a2a8a54 <redacted> + 176
        19  CoreFoundation                      0x000000018a2a3920 <redacted> + 1040
        20  CoreFoundation                      0x000000018a2a31f0 CFRunLoopRunSpecific + 436
        21  GraphicsServices                    0x000000018c51c584 GSEventRunModal + 100
        22  UIKitCore                           0x00000001b71ef4c0 UIApplicationMain + 212
        23  App2                                0x00000001007d2868 App2 + 3909736
        24  App2                                0x000000010079516c App2 + 3658092
        25  App2                                0x000000010079512c App2 + 3658028
        26  App2                                0x000000010042f1a0 App2 + 94624
        27  App2                                0x00000001006f94c8 App2 + 3019976
        28  App2                                0x0000000101558050 mono_pmip + 24712
        29  App2                                0x00000001015c4f2c mono_pmip + 470884
        30  App2                                0x00000001015ca1e8 mono_pmip + 492064
        31  App2                                0x000000010153ee58 App2 + 17985112
        32  App2                                0x000000010166e258 _Z9__isctypeim + 47160
        33  App2                                0x000000010042f098 App2 + 94360
        34  libdyld.dylib                       0x0000000189d62bb4 <redacted> + 4
     occurred

Best Answer

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    Check SqlDBController.designer.cs to see if BtnSaveRecord_TouchUpInside exists , and i guess you didn't implement it in SqlDBController.cs.

  • ranju_ranju_ Member ✭✭

    @ColeX said:
    Check SqlDBController.designer.cs to see if BtnSaveRecord_TouchUpInside exists , and i guess you didn't implement it in SqlDBController.cs.

    Can you please let me know how should I create it. Because as I can see
    'partial void BtnSaveRecord_TouchUpInside`(UIKit.UIButton sender) ' is automatically generated both in 'SqlDBController.designer.cs and SqlDBController.cs `when we double click on the button in storyboard. But in case of using btnSaveRecord.TouchUpInside within ViewdidLoad() method it is not the case. So Do I need to implement these manually in case of btnSaveRecord.TouchUpInside?

  • ranju_ranju_ Member ✭✭

    @ColeX said:
    @ranju_

    But in case of using btnSaveRecord.TouchUpInside within ViewdidLoad() method it is not the case.

    Here is the problem , you said BtnSaveRecord_TouchUpInside exists in SqlDBController.cs , this is because you have double clicked the button in storyboard ,it automatically generated this method , then you can handle stuffs in this method , you should not assign a new TouchUpInside event to the button in ViewdidLoad.

    Got it.. thanks!. What I had done is that I had commented automatically generated methods both in SqlDBController.cs and
    'SqlDBController.designer.cs' and was trying to use btnSaveRecord.TouchUpInside. Actually apart from commenting the autogenerated partial methods, I had to remove the BtnSaveRecord_TouchUpInside event as well using the story board.

Sign In or Register to comment.