美文网首页
CityResultViewController

CityResultViewController

作者: 一世沧桑画 | 来源:发表于2018-05-31 20:00 被阅读0次

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!

    }

}

相关文章

网友评论

      本文标题:CityResultViewController

      本文链接:https://www.haomeiwen.com/subject/uplcsftx.html