简体   繁体   中英

Pop up with table view in search bar, swift 2

I'm trying manipulate with Google places and autocomplete, about autocomplete from Google places I got the results but I wish put the results in a search bar with table view in front of Google maps, like a pop up. But I just found examples with search bar and table view and anything more behind them. I'm looking foward do something like the image below.

Example about pop up with table view in front of maps

Any help would be appreciated.

NOTE: I have never personally done this, but here's my theory:

The UISearchBar is a nifty tool in that you can hook a delegate up to it to control its actions. Below is a screenshot of the documentation which can be found here: link .

截图

So, what I would do is to set the UISearchBar's to whatever it's surrounding class is. Then, implement your delegate methods so that when any of those methods shown above in the picture are called, the surrounding class will segue to a UIPopoverPresentationController, which in turn will have a UITableView within it. (The popover will literally "pop over" the rest of the screen.)

You will have to make sure that the class you have set as the delegate implements the UISearchBarDelegate protocol. It will look something like this:

class Foo: UISearchBarDelegate {
    /* stuff */
}

After that, all the data configuration is up to you. Again, this is all in theory as I haven't actually implemented this myself. If I got anything wrong, please tell me.

Good luck.

EDIT: To respond to Dan L's comment on the initial question, it is actually is possible to have a popover present without going modal on an iPhone (or any compact screen). You have to set the presenting class as the delegate of the UIPopoverPresentationController an then implement a delegate method like this:

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.None
}

All the code is doing is preventing the popover from going modal ever.

The thing that I was looking for it was the popover. I would like to use a popover as I mentioned before, I found out some solutions similar here :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM