iphone keyboard without textview

jonydep picture jonydep · Sep 24, 2009 · Viewed 10.9k times · Source

is it possible to bring up the keyboard in an iphone app without a textview? or will i have to have an invisible textview?

if so, how do you programatically create a textview and then bring up the keyboard (without the user having to tap the textview)? the only examples i can find use interface builder..

Answer

klaaspieter picture klaaspieter · Sep 24, 2009

The only (valid) way to show the keyboard is to have a textfield that is first responder. You can hide it and make it first responder programmatically by calling becomeFirstResponder on the hidden textfield.

You can create a UITextView programmatically by doing something like this (assume aRect and view exist)

var textView = [[[UITextView alloc] initWithFrame:aRect] autorelease];
[view addSubview:textView];

[textView becomeFirstResponder];