mapbox / mapbox-search-ios

Search SDK for iOS with preconfigured UI in Swift
https://docs.mapbox.com/ios/search/guides/
Other
15 stars 20 forks source link

SearchUI Bug #7

Closed JanTG1 closed 2 years ago

JanTG1 commented 2 years ago

I have been using SearchUI for a while and everything worked well. However, I have recently noticed that I can no longer edit Favorites I have already set inside the SearchUI due to a UI Bug. I can create new Favorites but when pressing the three dots next to a favorite inside SearchUI, the Console throws me the following error:

[Presentation] Attempt to present <UIAlertController: 0x10d82dc00> on <X_One.OriginViewController: 0x10210b3e0> (from <X_One.OriginViewController: 0x10210b3e0>) whose view is not in the window hierarchy.

Weirdly enough, OrigiginViewController is just the first ViewController the App starts on, it handles sign-in status and creates a tab bar controller, on whom the SearchUI sits inside one of the tabs. Why am I getting such a weird error? OriginViewController shound not have anything to do with SearchUI... I am using Search v1.0.0-beta.15 and SearchUI v1.0.0-beta.15 together with MapboxMaps v 10.0.1.

don1ck commented 2 years ago

Hi @JanTG1, Looks like OriginViewController is a rootViewController of current window, and it's somehow not in a view hierarchy.

This is how we present AlertController in SearchUI:

        guard let controller = window?.rootViewController else {
            assertionFailure("Unexpected controller missing")
            return
        }
        controller.present(actionSheetController, animated: true, completion: nil)

Thanks for the report, we will investigate a better way to present that alert. Meanwhile you can try to set your tabbar (or some other controller) as window?.rootViewController.

JanTG1 commented 2 years ago

Hey @don1ck , I have tried, but: -setting it to my originViewController only added the SearchUI Silouette, meaning it was a grey box without content. -Setting it to self completely broke the app -Setting it to anything else didn't work at all

I wonder if I have made a mistake setting up SearchUI? This is how my setup looks like: //SearchUI setup searchController.delegate = self let panelController = MapboxPanelController(rootViewController: searchController) addChild(panelController)

I have obviously also added the SearchControllerDelegate Extention to my VC with the three mandatory Functions.

don1ck commented 2 years ago

Your SearchUI setup is correct. Looks like you need to figureout whats wrong with rootViewController, why its view not in a view hierarchy. Its mean OriginViewController.view not added as subview to the window. How does it creates and stores tabbar?

JanTG1 commented 2 years ago

Hey don1ck, sorry to reply so late, I have been very busy with other parts of the app and have pushed that issue back, which still remains to this day. Since when I opened this issue I have restructured a few things, but the issue stays the same.

I have a root view controller, which is the one that loads when the app starts. From there I create a Tabbar controller with 3 NavigationControllers, each staring a root ViewController for that NavigationController.

One of those NavigationControllers is the view that contains my MapView and the Search. That means that the root view controller at this point should theoretically be the MapView Controller, but the error always says startVC (which is my new root view controller I just talked about). I have no idea why that is and how to change it.

JanTG1 commented 2 years ago

Hello @don1ck, as of today, the issue still persists. I have pretty much-tried everything I could think of but the error is still the same. Any suggestions?

sarochych commented 2 years ago

Hi @JanTG1 , Thanks for your explanation, I've reopened the issue.

The issue is on SDK side, error is correct. We can't just present smth on the window rootViewController, since we don't control navigation stack. I'll provide a fix for this issue in the next release.

sarochych commented 2 years ago

@JanTG1 I've opened an MR with a potential fix. Could you please check whether the fix helps in your setup? Thanks in advance!

JanTG1 commented 2 years ago

@sarochych thanks for the quick reply! I'm sorry but I have no idea how to test that MR using cocoapods. Is there a way to pull that specific commit? I am still on beta15 but I will def. be updating to the newest beta34 once you release it.

sarochych commented 2 years ago

Fixed in beta.34.