我找不到如何上限 EntryElement
我preFER继承和事件太:-)试试这个:
I prefer inheritance and events too :-) Try this:
class MyEntryElement : EntryElement {
public MyEntryElement (string c, string p, string v) : base (c, p, v)
{
MaxLength = -1;
}
public int MaxLength { get; set; }
static NSString cellKey = new NSString ("MyEntryElement");
protected override NSString CellKey {
get { return cellKey; }
}
protected override UITextField CreateTextField (RectangleF frame)
{
UITextField tf = base.CreateTextField (frame);
tf.ShouldChangeCharacters += delegate (UITextField textField, NSRange range, string replacementString) {
if (MaxLength == -1)
return true;
return textField.Text.Length + replacementString.Length - range.Length <= MaxLength;
};
return tf;
}
}
也读米格尔的警告(编辑我的职位)位置:MonoTouch.Dialog:对于EntryElement