MvvmCross Failed to create target binding for Edit

2019-02-24 08:17发布

问题:

I have an application which binds to EditingDidBegin. It works fine on the iPhone Simulator (iOS 7) but when running on an actual iPhone I get the following warning message:

MvxBind:Warning: 1.29 Failed to create target binding for to EditingDidBegin

The binding code for the controls is:

var set = this.CreateBindingSet<InventoryBalanceView, InventoryBalanceViewModel>();
set.Bind(StoreroomLabel).To(vm => vm.StoreRoomCaption);
set.Bind(StoreroomTextField).To(vm => vm.StoreRoom);
set.Bind(ItemNumberLabel).To(vm => vm.ItemNumberCaption);
set.Bind(ItemNumberTextField).To(vm => vm.ItemNumber);
set.Bind(BinNumberLabel).To(vm => vm.BinNumberCaption);
set.Bind(BinNumberTextField).To(vm => vm.BinNumber);
set.Bind(QuantityLabel).To(vm => vm.QuantityCaption);
set.Bind(QuantityTextField).To(vm => vm.Quantity);
set.Bind(SubmitButton).To(vm => vm.SetFocusCommand);
set.Bind(DeleteButton).To(vm => vm.DeleteCommand);
      set.Bind(NavigationItem.RightBarButtonItem).To(vm => vm.ScanStoreRoomCommand);
set.Bind(DeleteButton).For(b => b.Hidden).To(vm => vm.IsDeleteButtonHidden);

set.Bind(SubmitButton).For("Title").To(vm => vm.SubmitButtonTitle);
set.Bind(DeleteButton).For("Title").To(vm => vm.DeleteButtonTitle);

set.Bind(StoreroomTextField).For("EditingDidBegin").To(vm =>  vm.SetFocusCommand).CommandParameter("StoreRoom");
set.Bind(ItemNumberTextField).For("EditingDidBegin").To(vm => vm.SetFocusCommand).CommandParameter("ItemNumber");
set.Bind(BinNumberTextField).For("EditingDidBegin").To(vm => vm.SetFocusCommand).CommandParameter("BinNumber");
set.Bind(QuantityTextField).For("EditingDidBegin").To(vm => vm.SetFocusCommand).CommandParameter("Quantity");

set.Apply();

I did change the project settings to Link All Assemblies, but that doesn't seem to have had any impact on the issue.

Any idea what's wrong with my code, or how to troubleshoot the issue?

Thanks for your help!

回答1:

This type of message - coupled with the 'it works in the simulator' evidence - almost always means that the linker has removed the symbol.

Instead of "change the project settings to Link All Assemblies", can you add a line to "LinkerPleaseIgnore.cs" (or to some other file) which tricks the linked into including the event.

e.g. include a file like https://github.com/slodge/NPlus1DaysOfMvvmCross/blob/master/N-38-Maps/Mappit.Touch/LinkerPleaseInclude.cs with a method like:

    public void Include(UITextField textField)
    {
        textField.Text = textField.Text + "";
        textField.EditingChanged += (sender, args) => { textField.Text = ""; };
        textField.EditingDidBegin += (sender, args) => { textField.Text = ""; };
        textField.EditingDidBegin -= (sender, args) => { textField.Text = ""; };
    }

This will hopefully trick the linker into including the textField.EditingDidBegin symbol



标签: mvvmcross