Question

My iPhone app (based on the "Single View Application" of Xcode) has a UITextView (say: myTextView) that I want the user to be able to edit. I was setting it to editable, and all was working fine (I didn't even have to invoke becomeFirstResponder).

Then I moved it in another UIWindow (say: newWindow) (on top of the main/root/key one that is called self.window (of the Single View App.)).

But now, when I click on the UITextView, the keyboard does not show.

Everything works if I do this:

[myTextView setEditable:YES];
[myTextView becomeFirstResponder]; // ugly...and I do not need it, but I added it just in case...
[self.window addSubview:newWindow];

but the keyboard is shown immediately (since I set becomeFirstResponder) that is not nice. But if I remove the becomeFirstResponder line, the keyboard does not show at all!

If I move the [self.window addSubview:newWindow] line above, then no matter what I do, the keyboard is not activated...

[self.window addSubview:newWindow]; // this is how it should be... but,
[myTextView setEditable:YES];
[myTextView becomeFirstResponder]; // even when I enter this, it's not working :-(

I tried [newWindow makeKeyAndVisible] nothing. I tried to add a touch delegate and detect a touch (or a gesture) on the UITextView, they work (I get the NSLog message I included), but again, no keyboard. I even tried to add another field (of the main window) on top of newWindow (so as to have a main window element on top), still no luck...

What am I missing?

Was it helpful?

Solution

You shouldn't add a UIWindow as a subview. Instead, windows are shown either by calling -[UIWindow makeKeyAndVisible], or -[UIWindow setHidden:NO] if you don't want it to receive key events.

It's rare that you need to use multiple windows though. Just using a normal UIView add adding that as a subview will do in many cases.

EDIT: I had a confusing remark before about "assigning to a screen". UIWindow has a property "screen", which you can assign to if you want to display the window on another screen than the main screen. You don't need to care about that for your use case, though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top