2017-09-15 3 views
0

Xcode 7.3.1에서이 문제가 발생합니다. 기본적으로지도에 검색 창을 추가하고 있습니다.유형 "localSearch"의 값에는 "start"멤버가 없습니다?

localSearch.start에서
func searchBarSearchButtonClicked(searchBar: UISearchBar){ 
    searchBar.resignFirstResponder() 
    dismissViewControllerAnimated(true, completion: nil) 
    if self.mapView.annotations.count != 0{ 
     annotation = self.mapView.annotations[0] 
     self.mapView.removeAnnotation(annotation) 
    } 
    localSearchRequest = MKLocalSearchRequest() 
    localSearchRequest.naturalLanguageQuery = searchBar.text 
    localSearch = MKLocalSearch(request: localSearchRequest) 
    localSearch.start{ (localSearchResponse, error) -> Void in 
     if localSearchResponse == nil{ 
      let alertController = UIAlertController(title: nil, message: "Place Not Found", preferredStyle: UIAlertControllerStyle.alert) 
      alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.default, handler: nil)) 
      self.present(alertController, animated: true, completion: nil) 
      return 

, 나는 점점 오전 : 유형 MKLocalSearch의

"값을 여기에

import UIKit 
import MapKit 

class FirstViewController: UIViewController, UISearchBarDelegate { 

var searchController:UISearchController! 
var annotation:MKAnnotation! 
var localSearchRequest:MKLocalSearchRequest! 
var localSearch:MKLocalSearch! 
var localSearchResponse:MKLocalSearchResponse! 
var error:NSError! 
var pointAnnotation:MKPointAnnotation! 
var pinAnnotationView:MKPinAnnotationView! 

@IBAction func showSearchBar(sender: AnyObject) { 
    searchController = UISearchController(searchResultsController: nil) 
    searchController.hidesNavigationBarDuringPresentation = false 
    self.searchController.searchBar.delegate = self 
    presentViewController(searchController, animated: true, completion: nil) 


} 

@IBOutlet var mapView: MKMapView! 

override func viewDidLoad() { 


    super.viewDidLoad() 

    let initialLocation = CLLocation(latitude: 47.6062, longitude: -122.3321) 

    let regionRadius: CLLocationDistance = 1000 
    func centerMapOnLocation(location: CLLocation) { 
     let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, 
                    regionRadius * 2.0, regionRadius * 2.0) 
     mapView.setRegion(coordinateRegion, animated: true) 
    } 

    centerMapOnLocation(initialLocation) 


} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

오류가 발생 단편이다 : 여기 컨텍스트에 대한 코드의 첫 번째 부분입니다 회원이 없습니다. "

나는 아주 새로 입니이다. 오류가 무엇인지에 관해 꽤 혼란 스러웠습니다.

은 또한 얻을 :

"예상 분리", ""

을 마지막 줄에 3 년. 그러나 그것을 변경하더라도 오류는 계속 발생합니다. 두 사람이 관련 될 수 있습니까?

+0

UIAlertControllerStyle.Alert에 프로젝트를 청소 시도하고 코드를 다시 실행 변경할 필요가 있다고 생각, 당신의 코드는, – 3stud1ant3

+0

3stud1ant3 @ 청소와 실행하려고 잘 보인다 빌드 실패 :/그 전에 더 많은 코드를 포함해야합니까? 비록 내가 거기에 어떤 오류를 볼 수는 없지만 .. – Aleks

+0

네, 좀 더 코드를 추가하십시오 스위프트 2 또는 스위프트 3을 사용하고 있습니까 – 3stud1ant3

답변

0

당신이 swift (SWIFT 2.2)의 이전 버전을 사용하고 있기 때문에 그래서 당신이 시도 분리기의 오류 ,를 들어

localSearch.startWithCompletionHandler { ... //this is for swift 2.2 

localSearch.start { ...  //this is for swift 3 

교체

필요가 있다고 생각 :

UIAlertActionStyle.Default 

대신

UIAlertActionStyle.default 

참고 : 난 당신이 또한 UIAlertControllerStyle.alert

+1

완벽한 덕분에 도움 :) – Aleks

관련 문제