I had the copy and define option built in with the UIWebView. It worked just fine on the iPad but on the iPhone, it only works once when I highlight the text and use the dictionary and the second time I tried it, it doesn't show up the popover. Any idea?
UPDATE: I am getting the following error as well when dismissing the dictionary on the iPhone: Unbalanced calls to begin/end appearance transitions for UIFallbackPresentationViewController
UPDATE: When I present a UIAlertView and cancel's it the dictionary works again. Wonder why?
At the moment there are 52 other questions on stackoverflow mentioning this error..
From reading a few i think the code apple is using is calling
presentModalViewController:
before the actual dictionary view is fully loaded.I think this is just a bug which apple has to solve, Rudolf Adamkovic's sample made it clear:
Choose Define
Debug console tell's you something like this:
I filed the bug at: https://bugreport.apple.com
Sample code: https://github.com/tiemevanveen/DefineBugDemoProject
All credit for this solution goes to @acue. Please see here.
Now, here's how I solved it. Printed [UIApplication sharedApplication].keyWindow after the dictionary had been presented to find out which subview was being given focus.
In that subview, registered for UIWindowDidBecomeKeyNotification
And. when the notification got posted, called the following method :-
Even though, I still see the error, the UIMenu & the Dictionary both continue to work as expected.
I am able to reproduce the error (shows up in console), but for me the popover works every time. So I wouldn't worry about it since it doesn't seem to be causing any crashes.
The only "work around" is to disable/replace the "Define" menu item. But the only way to do that is by writing a category for a private class (which is forbidden):
There are more "clever" ways of doing this without writing a category (method swizzling), but they are more dangerous.
If it's working I would just leave it alone. I have ARC enabled, so I'm not sure if that makes a difference.
Without seeing your code it is going to be really hard to give an answer to this question. It would be much easier if you would show your logic.
That being said, here are a couple of tips that might help:
viewDidAppear:animated
orviewDidLoad
, make sure you call the super methods.