I'm trying to use a custom control which extends UITextField so that I can hide the selection caret when my text field is activated. The text field has a picker as its inputview, so I don't want the blinking cursor in the text field when the picker is active. I'll eventually add something like the disclosure icon to the custom control, but for now I'm just trying to hide the cursor. I got this solution here.
My app is throwing an exception, though: Selector invoked from objective-c on a managed object of type TestCustomControl.PickerTextField (0xC8BC970) that has been GC'ed.
If I change my custom field back to UITextField I don't get the error.
This is my custom class:
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace TestCustomControl
{
[Register("PickerTextField")]
public class PickerTextField : UITextField
{
public override RectangleF GetCaretRectForPosition (UITextPosition position)
{
return RectangleF.Empty;
}
}
}
I've made my Outlet as both a UITextField and a PickerTextField, and I've tried running it from VS 2012 on my PC and Xamarin Studio 4.0.8 (build 2) on the Mac. In all scenarios, if in XCode I set the field to be UITextField it works fine (but I get a blinking cursor) and if I set it to be a PickerTextField I get the GC exception.
I can post the code for the whole project somewhere if it would help (it's just a single ViewController and View, the custom control class, a model for my picker, and the XIB file, plus the other files that get created for a new project).