13

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?

Tieme
  • 62,602
  • 20
  • 102
  • 156
adit
  • 32,574
  • 72
  • 229
  • 373
  • I think that warning message indicates the UIFallbackPresentationViewController is not getting instantiated completely before getting dismissed for some other view controller. – LJ Wilson Jan 06 '12 at 02:55
  • The issue is that I don't even have a UIFallbackPresentationViewController on my code, I think this is apple's – adit Jan 06 '12 at 03:09
  • Did you ever figure out the cause and/or a solution to this issue? – Sam J. Sep 14 '12 at 17:17
  • Which version of iOS are you running? Can you post some sample code or a sample project? I am having trouble replicating. – brynbodayle Oct 22 '12 at 14:15
  • Sample code: https://github.com/tiemevanveen/DefineBugDemoProject – Tieme Dec 04 '12 at 23:44

4 Answers4

11

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:

  • Create "Single View Application"
  • Add UITextView
  • Run it
  • Select a word in the text view
  • Choose Define

  • Debug console tell's you something like this:

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

I filed the bug at: https://bugreport.apple.com

Sample code: https://github.com/tiemevanveen/DefineBugDemoProject

Community
  • 1
  • 1
Tieme
  • 62,602
  • 20
  • 102
  • 156
  • 2
    Thanks of the bug report. :-) Slight correction: There are 52 other questions on stackoverflow that discuss the Unbalanced calls issue, most of them fixed by corrections to the code, among other things. But, only 2 questions (according to my search) discussing this particular issue with the mysterious _UIFallbackPresentationViewController message. Neither of the two questions have had a solution yet. – Sam J. Oct 25 '12 at 17:38
  • That's why i reported the bug. I'll look forward to apple's reaction. – Tieme Oct 25 '12 at 18:06
  • Apple: "Engineering has requested the following information in order to further investigate this issue: Please attach a sample project that demonstrates the issue you're reporting." - I've done so :) – Tieme Dec 04 '12 at 23:33
  • I am getting a similar error,@Tieme, but it is occurring when I attempt to load an image file through a mobile website I am viewing on my app's UIWebView. Do you have a suggestion as to how I can debug this issue after solving your problem? [My StackOverflowQuestion](http://stackoverflow.com/questions/15193253/xcode-unbalanced-calls-to-begin-end-appearance-transitions-for-uifileuploadfal) – JRoss Mar 13 '13 at 07:16
1

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:

  1. Make sure you are calling all appropriate super methods in your class. For example, if you override viewDidAppear:animated or viewDidLoad, make sure you call the super methods.
  2. Checkout this thread...maybe you are doing some sort of animation in an inappropriate place?
Community
  • 1
  • 1
Michael Frederick
  • 16,664
  • 3
  • 43
  • 58
  • 1
    Create "Single View Application", add `UITextView`, run it, select a word in the text view, choose Define and check the Debug Console. – Rudolf Adamkovič Oct 22 '12 at 14:42
  • I see the message but the popover shows every time. What problem is it causing in your app? – Michael Frederick Oct 22 '12 at 14:47
  • It's pretty random. For example, my gesture recognisers for `UIImageView`s don't work. I'd like to find out the root cause, because I find it pretty dangerous to ship an app with such a "russian roulette" issue. :) – Rudolf Adamkovič Oct 22 '12 at 15:09
  • I'd like to add to the.. well.. randomness.. for lack of a better word. :-) In iOS 5, I was only experiencing this in UIWebViews (UITextviews were fine in my experience, no warning messages, no weird behavior). iOS 6 brought this thing to UITextViews too. – Sam J. Oct 25 '12 at 17:28
0

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):

@interface UIWebBrowserView : UIView

@end

@interface UIWebBrowserView (Add)


@end

@implementation UIWebBrowserView (Add)
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if(action == @selector(_define:))
        return NO;
    return [super canPerformAction:action withSender:sender];
}
@end

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.

Luke
  • 13,678
  • 7
  • 45
  • 79
0

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 :-

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

Even though, I still see the error, the UIMenu & the Dictionary both continue to work as expected.

Community
  • 1
  • 1
Sam J.
  • 685
  • 1
  • 8
  • 22