按钮点击

时间:2018-01-27 10:24:59

标签: c# xamarin xamarin.ios mvvmcross

我有一个用户将在文本字段中输入一些文本的视图。当用户按下按钮时,我需要获取一些数据。但是当我按下按钮并出现以下错误时,我的应用程序崩溃了:

Objective-C exception thrown.
Name: NSInvalidArgumentException Reason: -[SchoolSelectionView UIButton4156_TouchUpInside:]: unrecognized selector sent to instance 0x7fb1ae547220
Native stack trace:
    0   CoreFoundation                      0x000000011611e12b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000116dc5f41 objc_exception_throw + 48
    2   CoreFoundation                      0x000000011619f024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   UIKit                               0x0000000109538f51 -[UIResponder doesNotRecognizeSelector:] + 295
    4   CoreFoundation                      0x00000001160a0f78 ___forwarding___ + 1432
    5   CoreFoundation                      0x00000001160a0958 _CF_forwarding_prep_0 + 120
    6   UIKit                               0x0000000109306972 -[UIApplication sendAction:to:from:forEvent:] + 83
    7   UIKit                               0x0000000109485c3c -[UIControl sendAction:to:forEvent:] + 67
    8   UIKit                               0x0000000109485f59 -[UIControl _sendActionsForEvents:withEvent:] + 450
    9   UIKit                               0x0000000109484e86 -[UIControl touchesEnded:withEvent:] + 618
    10  UIKit                               0x000000010937c807 -[UIWindow _sendTouchesForEvent:] + 2807
    11  UIKit                               0x000000010937df2a -[UIWindow sendEvent:] + 4124
    12  UIKit                               0x0000000109321365 -[UIApplication sendEvent:] + 352
    13  UIKit                               0x0000000109c6da1d __dispatchPreprocessedEventFromEventQueue + 2809
    14  UIKit                               0x0000000109c70672 __handleEventQueueInternal + 5957
    15  CoreFoundation                      0x00000001160c1101 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    16  CoreFoundation                      0x0000000116160f71 __CFRunLoopDoSource0 + 81
    17  CoreFoundation                      0x00000001160a5a19 __CFRunLoopDoSources0 + 185
    18  CoreFoundation                      0x00000001160a4fff __CFRunLoopRun + 1279
    19  CoreFoundation                      0x00000001160a4889 CFRunLoopRunSpecific + 409
    20  GraphicsServices                    0x00000001189b09c6 GSEventRunModal + 62
    21  UIKit                               0x00000001093055d6 UIApplicationMain + 159
    22  ???                                 0x0000000135456508 0x0 + 5188707592
    23  ???                                 0x0000000135456133 0x0 + 5188706611

我的观点代码:

var set = this.CreateBindingSet<SchoolSelectionView, SchoolSelectionViewModel>();
        set.Bind(txtSchoolCode).To(vm => vm.SchoolCode);
        set.Bind(btnEnter).To(vm => vm.SchoolEnterCommand);
        set.Apply();

ViewModel中的代码:

private IMvxCommand _loginCommand;
    public virtual IMvxCommand SchoolEnterCommand
    {
        get
        {
            _loginCommand = _loginCommand ?? new MvxCommand(CheckSchoolCode);
            return _loginCommand;
        }
    }

    private async void CheckSchoolCode()
    {
        var response = _schoolService.GetSchoolDetails(SchoolCode);
        if (response.Result != null)
        {
            await _navigationService.Navigate<LoginViewModel, SchoolModel>(response.Result);
        }
        else
        {
            Mvx.Resolve<IUserDialogs>().Alert("Invalid login credentials", "Error", "Done");
        }
    }

1 个答案:

答案 0 :(得分:0)

您似乎已在StoryBoard中为btnEnter定义了一个TouchUpInside事件。

请检查控制器的designer.cs文件是否存在代码[Action ("UIButton4156_TouchUpInside:")]。你可以在按钮的属性窗口=&gt;的StoryBoard文件中找到该事件。事件=&gt;在里面。尝试删除它并再次部署。

双击Storyboard中的按钮可能会导致此问题。