UrbanApps / Armchair

A simple yet powerful App Review Manager for iOS and OSX in Swift
MIT License
1.2k stars 137 forks source link

getRootViewController won't work correctly. #81

Closed RyogaK closed 7 years ago

RyogaK commented 8 years ago

I'm not in detail, but nextResponder of the item in keyWindow.subviews is keyWindow in my case. I think it should be discussed.

How about use following logic? At least, the following works for me.

var queuedSubviews = [UIView]()
queuedSubviews.appendContentsOf(window.subviews)

while !queuedSubviews.isEmpty {
    let subView = queuedSubviews.removeFirst()
    if let responder = subView.nextResponder() {
        if responder.isKindOfClass(UIViewController) {
            return topMostViewController(responder as? UIViewController)
        }
    }
    queuedSubviews.appendContentsOf(subView.subviews)
}

I can make pull request if needed 😆

scottrhoyt commented 7 years ago

I'm not sure iterating through the view controllers is the right approach. There are a lot of assumptions that need to be made, and even then the view controller you find might not currently be in the right state to present a modal because it is in the process of transitioning.

Perhaps a better approach would be to create a new window with an empty view controller as root and present from that view controller. The dismissal of the modal can then hide the widow and release it. This is the approach that I have used in situations like this and it works well.

RyogaK commented 7 years ago

@scottrhoyt That makes sense. your approach sounds good to me. Thank you!