Search code examples
swiftuitableviewuinavigationcontrolleruinavigationbargoogle-places-api

First row of tableview partially covered


I am implementing the Google Places API and when I follow the code they are providing the first row is being covered by the navigation bar. I have tried it with the title included and also without the title text. In both instances, the top part of that row is covered. Do I need to add something to move the tableview down?

enter image description here

import UIKit
import GooglePlaces

class SearchGooglePlacesController: UIViewController {

var resultsViewController: GMSAutocompleteResultsViewController?
var searchController: UISearchController?
var resultView: UITextView?

override func viewDidLoad() {
    super.viewDidLoad()
    navigationItem.title = "Search for Resturant"
    view.backgroundColor = .seGrey
    resultsViewController = GMSAutocompleteResultsViewController()
    resultsViewController?.delegate = self

    searchController = UISearchController(searchResultsController:      
resultsViewController)
    searchController?.searchResultsUpdater = resultsViewController

    searchController?.searchBar.sizeToFit()
    navigationItem.titleView = searchController?.searchBar

    definesPresentationContext = true
    searchController?.hidesNavigationBarDuringPresentation = false

}
}

extension SearchGooglePlacesController:    
GMSAutocompleteResultsViewControllerDelegate {

func resultsController(_ resulstsController:   
 GMSAutocompleteResultsViewController, didAutocompleteWith place:  
 GMSPlace) {
    searchController?.isActive = false

    print("Place name: \(place.name)")
    print("Place attributions: \(place.types)")
    print("Place location: \(place.formattedAddress ?? "")")
    let name = place.name
}

func resultsController(_ resultsController: GMSAutocompleteResultsViewController,
                       didFailAutocompleteWithError error: Error){
    // TODO: handle the error.
    print("Error: ", error.localizedDescription)
}

// Turn the network activity indicator on and off again.
func didRequestAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
    UIApplication.shared.isNetworkActivityIndicatorVisible = true
}

func didUpdateAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
    UIApplication.shared.isNetworkActivityIndicatorVisible = false
}
}

Solution

  • I had to use this in the viewDidLoad self.extendedLayoutIncludesOpaqueBars = true self.edgesForExtendedLayout = .top