I'm attempting to embed an editable UITextView inside a UIPopoverController, with... strange results. The steps I've taken are:
- Create a custom UIViewController class, and create a .xib file with that controller with a UITextView inside it.
- When the UI action that should bring up the controller occurs (touch up inside), I instantiate the controller and its view from the .xib file.
- I create a new UIPopoverController, with the view controller I just instantiated as the content view.
- I present it with presentPopoverFromRect:inView:permittedArrowDirections:animated:
Here's some example code:
- (void)noteButtonPressed:(id)sender {
self.noteview = [[MyTextPopupViewController alloc] initWithNibName:@"MyTextPopupViewController" bundle:nil ];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:self.noteview];
self.popover = popoverController;
self.popover.delegate = self;
[self.popover presentPopoverFromRect:((UIView*)sender).frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
Then, inside MyTextPopupViewController, I make sure the the text view is the first responder to bring up the keyboard:
- (void)viewDidAppear:(BOOL)animated {
[self.view becomeFirstResponder];
[super viewDidAppear:animated];
}
And that all works... right until it doesn't. Sometimes, it works perfectly; other times, either immediately or after a few keystrokes, the application crashes by exiting the main event loop (!). No exception is thrown (at least not that the lldb catches), but the application simply stops, both on the simulator and on hardware.
Any thoughts? Has anyone gotten this working successfully, or knows for sure that it does not?
MyTextPopupViewController
do you implementtextView:shouldChangeTextInRange:replacementText:
(or any of the other delegate methods that might be causing problems here)? If so, please post that code. – lnafzigerviewDidAppear
so that super is properly called before you do anything. – lnafzigerUITextView
the first responder instead of the view controller – Jaysen Marais