class CityResultViewController:UIViewController,UITableViewDataSource{
? ? ? ? ?var passString :String=""
? ? ? ? ? var tableData? : [city]?
? ? ? ? ?var table :UITableView?
? ? override func viewDidLoad() {
? ? ? ? ? ? ? ? ? ?super.viewDidLoad()
? ? ? ? ? ? ? ? ? ?self.view.backgroundColor = UIColor.white
? ? ? ? ? ? ? ? ? self.navigationItem.title = "\"\(passString)\"的搜索結果"
? ? ? ? //實例化表格
? ? ? ? table=UITableView.init(frame:CGRect(x:0, y:0, width:ScrW, height:ScrH))
? ? ? ? table?.dataSource = self as! UITableViewDataSource
? ? ? ? self.view.addSubview(table!)
? ? }
? ? override func viewWillAppear(_animated:Bool) {
? ? ? ? ? ? ? ? let urlSer =URLService()
? ? ? ? urlSer.searchCity(search:self.passString, vc:self)
? ? ? ? {(data,success)in
? ? ? ? ? ? if ?!success {
? ? ? ? ? ? ? ? return
? ? ? ? ? ? }
? ? ? ? ? ? self.tableData= dataas? [city]
? ? ? ? ? ? DispatchQueue.main.async{
? ? ? ? ? ? ? ? self.table?.reloadData()
? ? ? ? ? ? }
?? ? ? ?}
? ? }
? ? func tableView(_tableView:UITableView, numberOfRowsInSection section:Int) ->Int{
? ? ? ? if ?let count =tableData?.count? {
? ? ? ? ? ? return count
? ? ? ? }
? ? ? ? return0
? ? }
? ? func tableView(_tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell{
? ? ? ? let identifier ="cell"
? ? ? ? var cell = tableView.dequeueReusableCell(withIdentifier: identifier)
? ? ? ? if cell ==nil{
? ? ? ? ? ? cell =UITableViewCell.init(style: .subtitle, reuseIdentifier: identifier)
? ? ? ? }
? ? ? ? let ?one =self.tableData![indexPath.row]as? city
? ? ? ? cell?.textLabel?.text= one?.city
? ? ? ? cell?.detailTextLabel?.text= one?.content
? ? ? ? return cell!
? ? }
}