7

I keep getting the following error when I dismiss the dictionary that opens from tapping Define on the UIMenuController in a UIWebView on the iPhone:-

Unbalanced calls to begin/end appearance transitions for <_UIFallbackPresentationViewController: 0x10ab9640>.

And after this error, the UIMenuController stops showing up, in any UIWebView.

Any ideas what's going on here?

UPDATE: The error actually shows up when the dictionary view is opening, not when dismissing it.

UPDATE 2: The error is app wide. Anywhere there is selectable text (i.e. webview, textview etc.) I can only use the define dictionary once. This error shows up & then, I have to quit the app & start it again, to use the dictionary.

Sam J.
  • 685
  • 1
  • 8
  • 22
  • 1
    FYI. I can see the same warning on the Simulator and device, but the menu and dictionary continues to function for me afterwards. – Mike Weller Oct 18 '12 at 15:15
  • @Mike Weller: I wish it were the same for me, I have two apps. In one app, the dictionary and the menu, both continue to work, despite of the warning. For the second app though, the dictionary stops working after the first time. Can't even get the menu to show again, once the dictionary has been presented. – Sam J. Oct 18 '12 at 15:58
  • Do you have any crazy view controller hierarchy stuff going on? Like directly inserting view controller views without using the correct containment APIs? – Mike Weller Oct 19 '12 at 07:28
  • That was the first thing that came to my mind too. But, that would be a no. – Sam J. Oct 19 '12 at 11:06
  • There is a great answer and discussion on this question: http://stackoverflow.com/questions/8751680/uiwebview-and-define-dictionary – brynbodayle Oct 25 '12 at 13:33
  • @bbodayle: Thanks for bringing it to my attention! – Sam J. Oct 25 '12 at 17:39

2 Answers2

4

Finally found an answer for this. When the dictionary gets presented by the system, its window gets focus (see makeKeyAndVisible: in UIWindow), which is great. The problem comes when dismissing where the window holding the dictionary doesn't properly give the main application window back focus.

If you print out the [UIApplication sharedApplication].keyWindow before and after the dictionary gets presented then you'll see how before your application window was keyAndVisible and afterwards it is a different window. For me, I had a separate window for app messages that lived on top of the status bar, and that one was what was keyAndVisible after the dictionary was dismissed.

So all I had to do to fix it was have the following override method in my UIWindow subclass that incorrectly received focus:

- (void) makeKeyWindow {
  AppDelegate * appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  [appDelegate.window makeKeyAndVisible];
}

I'm not sure how this will work for those if you without your own UIWindow that gets focused on, but absolute worst case you could add a dummy UIWindow that would receive focus and add the exact same piece of code from above.

acue
  • 56
  • 1
  • 4
  • What do you mean by "have the following override method in my UIWindow subclass"? The only UIWindow occurrence in my project is in appDelegate and if I make the subclass and put the function and override the method makeKeyWindow, it will not work because makeKeyWindow gets into infinite recursion. :-S – Sufian Feb 06 '13 at 05:39
  • @Sufian Try using nslog to get the result of [UIApplication sharedApplication].keyWindow after the dictionary has been presented & dismissed. The following code might help. NSLog(@"%@", [UIApplication sharedApplication].keyWindow); In my case, I was using a statusbar overlay which was becoming the key window. Registering for UIWindowDidBecomeKeyNotification in my statusbar overlay class and calling the code acue provided above when the notification got posted fixed this issue for me. – Sam J. Feb 09 '13 at 10:18
  • How do I know that the dictionary has been presented or dismissed? The viewWillAppear and viewWillDisappear methods aren't called. Can you please elaborate a little more? – Sufian Feb 15 '13 at 06:33
  • @Sufian The NSLog does not need to remain in your app, just put it in a method (like let's say a UIButton's Action, which you can call by tapping said button) that you can somehow call after the dictionary as been presented & dismissed. It's only purpose is to tell you which window has received focus incorrectly. – Sam J. Mar 18 '13 at 12:10
1

The error message suggests you start a transition but the call to the corresponding end method is missing.

  • Have you tried doing the transition without animation? (animated: NO)

  • Sometimes this behavior appears when using a switch statement and forgetting the break;

  • If you are performing a seque, do it in -viewDidAppear instead of -viewWillAppear

Hope it helped a bit! :)

Git.Coach
  • 3,032
  • 2
  • 37
  • 54
  • Thanks for the effort, but I'm not doing the transition, the system is, as the dictionary is presented by the default system UIMenu. Any help with how I might remove the animation from it would be appreciated. I do not have a switch statement, nor am I performing a seque. Thanks again for the effort! :-) – Sam J. Oct 23 '12 at 07:02