CityResultViewController

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!

? ? }

}

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容