第一行tableview部分覆盖

时间:2018-05-11 18:38:55

标签: swift uitableview uinavigationcontroller uinavigationbar google-places-api

我正在实施Google Places API,当我按照他们提供的代码时,导航栏会覆盖第一行。我已尝试过包含标题,也没有标题文字。在这两种情况下,该行的顶部都被覆盖。我是否需要添加一些内容来移动桌面视图?

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
}
}

1 个答案:

答案 0 :(得分:2)

我必须在viewDidLoad中使用它 self.extendedLayoutIncludesOpaqueBars = true self.edgesForExtendedLayout = .top