Reputation: 21
So I'm building an MVVM app in Xamarin. I'm working on the iOS view for a certain viewmodel right now, and the view contains a few RadioGroups to select items from lists, as well as some EntryElements to take text data from the keyboard. Now it works when you select items from lists, and then enter keyboard data. However, if you enter the keyboard data first, and then try to select items from the RadioGroup, I get a crash in Main.cs at this line:
UIApplication.Main(args, null, "AppDelegate");
Here's the error description:
MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[__NSCFString setRestorableResponder:]: unrecognized selector sent to instance 0x16744d90 at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) at MonoTouch.UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62 at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:45 at GreenRideGlobalMeterReading.iOS.Application.Main (System.String[] args) [0x00008] in /Users/developers/Desktop/GreenRideGlobalMeterReading/GreenRideGlobalMeterReading.iOS/Main.cs:17
I can't figure out what the hell is causing this - some weird MvvmCross or MonoTouch related framework error? Anyone else encountered this before or have an idea of how to fix it?
Upvotes: 1
Views: 465
Reputation: 619
It looks like you are forgetting to call the "ResignFirstResponder" of the keyboard. If the keyboard is up, and you try to click an element in another control, you need to first dismiss the keyboard using the:
textBox.ResignFirstResponder();
You can also add a delegate when initiating the textBox like this:
tbDescription = new UITextField ();
tbDescription.Placeholder = "Description...";
tbDescription.ReturnKeyType = UIReturnKeyType.Done;
tbDescription.ShouldReturn += (textField) =>
{
tbDescription.ResignFirstResponder ();
return true;
};
Try that out. I hope it helps. Good luck!
Upvotes: 0