Search code examples
iphonekeyboardiphone-softkeyboard

iphone keyboard without textview


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..


Solution

  • 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];