Thanks Tomasz! I have now managed to make it work. I used the following
variant of your example:
UITextField _textField = new UITextField(...);
_textField.ShouldReturn = DoReturn;
View.AddSubview(_textField);
with the event function:
bool DoReturn (UITextField tf)
{
tf.ResignFirstResponder ();
//did something in here.
return true;
}
/Robert
On Sun, 22 Apr 2012 22:27:39 +0200, Tomasz Cielecki wrote:
To define a TextField programmatically you should instantiate a
UITextField. I.e.:
UITextField _textField = new UITextField();
Now this has a lot of methods you can look up here:
http://docs.go-mono.com/?link=T%3aMonoTouch.UIKit.UITextField
for instance to set the text:
_textField.Text = "Just some text";
it has two nice events, one called Started another called Ended,
which
get triggered when a user starts typing and when a user has ended
typing, you could use those for finding out when something has been
typed into them. But there is also a delegate you can set called
ShouldEndEditing to find out if editing has ended.
_textField.ShouldEndEditing = delegate
{
//do something in here.
}
to close the keyboard you can do this:
_textField.ShouldReturn = delegate
{
_textField.ResignFirstResponder();
return true;
};
or if you have a submit button in that buttons event:
public void ButtonClick(object sender, EventArgs e)
{
_textField.ResignFirstResponder();
// Other stuff to perform
}
On Fri, Apr 20, 2012 at 10:52 PM, Robert Forchheimer
<[email protected]> wrote:
Hi, anyone knows how to define a textfield programmatically? I am
able to
produce the view (including the keyboard) but don't know how to
close it and
capture the user's text input.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch