1

私はビューコントローラでアドレスのオートコンプリートを設定しようとしているので、ユーザーはアドレス全体を入力する必要はなく、検索テキストフィールドの下から選択する必要があります。 AddNewAddressViewControllerがプロトコルに準拠していないSwift MapKit Autocomplete

タイプ「UITableViewDataSource」

を私は何をしないのです。私はというエラーを取得しています

import Foundation 
import UIKit 
import MapKit 


extension AddNewAddressViewController: MKLocalSearchCompleterDelegate { 

    func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) { 
     searchResults = completer.results 
     searchResultsTableView.reloadData() 
    } 

    func completer(_ completer: MKLocalSearchCompleter, didFailWithError error: Error) { 
     // handle error 
    } 
} 

class AddNewAddressViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 

    var searchCompleter = MKLocalSearchCompleter() 
    var searchResults = [MKLocalSearchCompletion]() 


    override func viewDidLoad() { 

     searchCompleter.delegate = self 

     searchCompleter.queryFragment = addressSearch.text! 

     searchResultsTableView.dataSource = self 

     super.viewDidLoad() 
    } 



    @IBOutlet weak var addressSearch: UITextField! 
    @IBOutlet weak var searchResultsTableView: UITableView! 


    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     let searchResultsCount = searchResults.count 
     return searchResultsCount 
    } 

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let searchResult = searchResults[indexPath.row] 
     let cell = UITableViewCell(style: .subtitle, reuseIdentifier: nil) 
     cell.textLabel?.text = searchResult.title 
     cell.detailTextLabel?.text = searchResult.subtitle 
     return cell 
    } 

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    } 


    @IBAction func defaultAddressButton(_ sender: Any) { 
    } 

    @IBAction func addAddressButton(_ sender: Any) { 
    } 

} 

:これは私のコントローラがどのように見えるかですか?

ありがとうございます。

答えて

1

あなたはSWIFT 3.0の下で要求されるcellForRowAtIndexPath宣言の最初のパラメータにアンダースコアを残し:結果

func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
[etc.] 

、あなたが期待されるシグネチャに一致する必要な機能を持っていません。