sammcewan / WYPopoverController

WYPopoverController is for the presentation of content in popover on iPhone / iPad devices. Very customizable.
Other
253 stars 74 forks source link

UIDocumentInteractionController incompatibility #35

Closed Thomas101 closed 9 years ago

Thomas101 commented 9 years ago

Hi,

I've found an incompatibility with the UIDocumentInteractionController in iOS8. If you include the WYPopoverController in your project then run this code...

@property (nonatomic, strong) UIDocumentInteractionController* documentInteractionController;

NSString* path = [[NSBundle mainBundle] pathForResource:@"Untitled" ofType:@"pages"];
NSURL* url = [NSURL fileURLWithPath:path];
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.documentInteractionController.delegate = self;
CGRect bottomCenter = CGRectMake((self.view.frame.size.width / 2) - 2, self.view.frame.size.height, 2, 2);
[self.documentInteractionController presentOpenInMenuFromRect:bottomCenter inView:self.view animated:YES];

The popover launches but now when you press the "More" button you end up in a recursive loop in the WYPopoverLibrary

- (void)sizzled_setPreferredContentSize:(CGSize)aSize
{
    [self sizzled_setPreferredContentSize:aSize];

    if ([self isKindOfClass:[UINavigationController class]] == NO && self.navigationController != nil)
    {
#ifdef WY_BASE_SDK_7_ENABLED
        if ([self respondsToSelector:@selector(setPreferredContentSize:)]) {
            [self.navigationController setPreferredContentSize:aSize];
        }
#endif
    }
}

As a pretty horrific fix I've done the following, but this is super brittle. It would be great to know what's actually up and get something in that's more re-usable

- (void)sizzled_setPreferredContentSize:(CGSize)aSize
{
    [self sizzled_setPreferredContentSize:aSize];

    if ([self isKindOfClass:[UINavigationController class]] == NO && self.navigationController != nil)
    {
#ifdef WY_BASE_SDK_7_ENABLED
        if ([NSStringFromClass([self class]) hasPrefix:@"_UIActivityUserDefaultsViewController"] == NO) {
            if ([self respondsToSelector:@selector(setPreferredContentSize:)]) {
                [self.navigationController setPreferredContentSize:aSize];
            }
        }
#endif
    }
}
Bluezen commented 9 years ago

Hello, This issue seems related to #22 and to what's happening when presenting a UIActivityViewController in a system popover.

Would you mind giving a try to the following fix? It should prevent the recursive loop even in your case:

- (void)sizzled_setPreferredContentSize:(CGSize)aSize
{
    [self sizzled_setPreferredContentSize:aSize];

    if ([self isKindOfClass:[UINavigationController class]] == NO && self.navigationController != nil)
    {
#ifdef WY_BASE_SDK_7_ENABLED
        if ([self.navigationController isEmbedInPopover]) {
            if ([self respondsToSelector:@selector(setPreferredContentSize:)]) {
                [self.navigationController setPreferredContentSize:aSize];
            }
        }
#endif
    }
}
Thomas101 commented 9 years ago

Yeah, I agree with you. That seems to have fixed the issue on my end.

Thanks very much!

Bluezen commented 9 years ago

Thank you for having checked!