0
votes

I'm attempting to embed an editable UITextView inside a UIPopoverController, with... strange results. The steps I've taken are:

  1. Create a custom UIViewController class, and create a .xib file with that controller with a UITextView inside it.
  2. 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.
  3. I create a new UIPopoverController, with the view controller I just instantiated as the content view.
  4. 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?

1
In MyTextPopupViewController do you implement textView:shouldChangeTextInRange:replacementText: (or any of the other delegate methods that might be causing problems here)? If so, please post that code.lnafziger
Also, you should switch the two lines in your viewDidAppear so that super is properly called before you do anything.lnafziger
I currently don't implement any of the UITextViewDelegate methods.Christophe
And reversing those lines in viewDidAppear: doesn't change the behavior.Christophe
it is definitely possible to have an editable UITextView in a popover. I have such a setup in a shipping app without issue (though I don't see anything obviously wrong with your code). I would suggest making the UITextView the first responder instead of the view controllerJaysen Marais

1 Answers

0
votes

I think the UIPopoverController instance needs to be a property in your code.