Comments (11)
I have encountered the exact same problem and I am not even using WYPopoverController to present the ActivityViewController. I am using the system provided UIPopoverController. This is strange.
from wypopovercontroller.
Ah, I did not see that that method was a UIViewController category method. That's why it is called even though I am not using WYPopoverController. Your temporary fix seems to be working on iOS 8.1 @Bluezen
from wypopovercontroller.
Yes, you are describing the exact same problem.
It is indeed because WYPopoverController
swizzle the setPreferredContentSize:
method of UIViewController
that the crash occurs even though we are not explicitly using WYPopoverController
.
My temporary solution is simply a safeguard, it prevents the faulty line to be called on iOS8 and could yield bad side effects. I chose to ignore it because I never use a UINavigationController in my WYPopovers... so be careful, this is not a fix!
Ok, after spending too much time again on it I might have a better idea of what the real problem is and much more importantly, I have a better understanding of what sizzled_setPreferredContentSize
does.
I wrongly assumed that there was an error in sizzled_setPreferredContentSize
but we are instead facing an unexpected side effect of messing with a widely used system method.
The recursive call that
[self.navigationController setPreferredContentSize:aSize];
creates is intended and
if ([self isKindOfClass:[UINavigationController class]] == NO && self.navigationController != nil)
is the safeguard that should stop it to loop indefinitely.
It seems that
[self.navigationController setPreferredContentSize:aSize];
is a necessary call to be able to resize a WYPopoverController dynamically but unfortunately the safeguard doesn't play its role well when a system UIPopover with a UINavigationController is the one to yield the call.
We have to understand why and how to stop the infinite loop in this case.
from wypopovercontroller.
Ok, what is happening is very strange. The issue has something to do with the fact that we are dealing with private classes. In the internal hierarchy of a presented UIActivityViewController there is what seems to be a subclass of UINavigationController
called _UIUserDefaultsActivityNavigationController
(visible after pushing the "more" button).
In our situation the erroneous call starting the infinite loop happens in sizzled_setPreferredContentSize
when self
is of kind _UIActivityUserDefaultsViewController
and self.navigationController
an instance of kind _UIUserDefaultsActivityNavigationController
.
The thing I cannot explain is what happen in this precise situation when the following message is sent:
[self.navigationController setPreferredContentSize:aSize];
The swizzled function sizzled_setPreferredContentSize
is called, which seems normal, but we are in the exact same configuration than before; self
is the same instance of _UIActivityUserDefaultsViewController
than before instead of being the instance of navigationController _UIUserDefaultsActivityNavigationController
. This causes the infinite loop.
I can only guess that the bizarre behavior is because the _UIUserDefaultsActivityNavigationController
is internally forwarding the setPreferredContentSize
to our instance of _UIActivityUserDefaultsViewController
, hence the exact same configuration and the loop... or something like that.
Anyway, the best solution I can come up with for the moment is to prevent the call to be made only in this precise situation:
- (void)sizzled_setPreferredContentSize:(CGSize)aSize
{
[self sizzled_setPreferredContentSize:aSize];
BOOL isPrivateUIActivityNavigationController = [NSStringFromClass(self.navigationController.class) isEqualToString:@"_UIUserDefaultsActivityNavigationController"];
if ([self isKindOfClass:[UINavigationController class]] == NO
&& self.navigationController != nil
&& isPrivateUIActivityNavigationController == NO)
{
#ifdef WY_BASE_SDK_7_ENABLED
if ([self respondsToSelector:@selector(setPreferredContentSize:)]) {
[self.navigationController setPreferredContentSize:aSize];
}
#endif
}
}
That prevents the crash to happen but doesn't break dynamic resize of WYPopover presenting a UINavigationController.
from wypopovercontroller.
Well, this still is not a perfect solution as you said, though thank you very much for trying to get to the bottom of the problem. This can happen on other private classes, so we need to come up with a better system.
from wypopovercontroller.
Yeah, you are right, this could happen with other private classes.
Maybe we should take the problem backwards, instead of preventing private classes to make a mess we should specify to do nothing if we are not dealing with a WYPopover.
from wypopovercontroller.
Yes, that's exactly what I was trying to say. Adding categories on UIViewController is a little bit dangerous IMHO.
from wypopovercontroller.
I agree with you, if possible we should avoid swizzle such methods of UIViewController. Maybe this should be refactored to be handled differently.
In the meantime I am suggesting this:
- (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] == NO) {
return;
} else if ([self respondsToSelector:@selector(setPreferredContentSize:)]) {
[self.navigationController setPreferredContentSize:aSize];
}
#endif
}
}
from wypopovercontroller.
👍 This happens to me too, when will a fix be released?
from wypopovercontroller.
The pull request in the original repo will resolve this issue.
nicolaschengdev#182
from wypopovercontroller.
I'll check this issue tomorrow
from wypopovercontroller.
Related Issues (20)
- KIF compatibility HOT 3
- Misalignment when rapidly changing orientation back and forth
- Popover not re-appearing after calling dismissPopoverAnimated HOT 2
- Popovers in landscape won't display correctly HOT 1
- UINavigationControllerDelegate method call crash
- iOS8 + iPhone 6+: crash in drawRect
- Resizing popover for different view controllers in the navigation stack?
- Incorrect popover offset if keyboard is visible
- Section header HOT 2
- Accessibility / UIAutomation HOT 2
- Presenting view controllers on detached view controllers is discouraged HOT 3
- popover not showing after segue
- how to remove UINavigationBar ? HOT 2
- How to closs popoverController when I tap the TableviewCell?
- Theme observer invokes -updateThemeUI multiple times
- Present Modal From WYPopoverController
- popover in a modally presented viewcontroller HOT 11
- Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x7fb0d15ce510 of class WYPopoverTheme was deallocated while key ... HOT 5
- Need layout adaptations for new iPhone X on iOS 11
- How to center popover after rotation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wypopovercontroller.