import Alamofire
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
var dicc:NSDictionary?
var dic1:NSArray = []
var table:UITableView?
var dict:NSDictionary = [:]
var data:NSMutableDictionary = [:]
var dictr:NSDictionary = [:]
override func viewDidLoad() {
super.viewDidLoad()
setUI()
resultData()
}
func setUI(){
let SecBar:UISearchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: 41, height: 41))
self.navigationItem.titleView = SecBar
// self.navigationItem.rightBarButtonItem UIBarButtonItem(barButtonSystemItem: “dasd”, target: self, action: .done, action:select(right))
self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(title:“daw”, style: UIBarButtonItem.Style.plain, target: self, action: #selector(self.right))
//表格
table = UITableView.init(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height), style: .grouped)
table?.delegate = self
table?.dataSource = self
let viewTop:UIView = UIView.init(frame: CGRect(x: 0, y: 0, width: 414, height: 200))
viewTop.backgroundColor = UIColor.red
let imgView:UIImageView = UIImageView.init(frame: CGRect(x: 0, y: 0, width: 414, height: 200))
imgView.image = UIImage(named: "Snip20181115_1")
viewTop.addSubview(imgView)
self.table?.tableHeaderView = viewTop
self.view .addSubview(table!)
// self.table?.register(newTableViewCell.self, forCellReuseIdentifier: “cells”)
self.table?.register( UINib(nibName: “newTableViewCell”, bundle: nil), forCellReuseIdentifier: “cells”)
}
@objc func right(){
print("sda" )
}
func resultData(){
Alamofire.request("http://live.ximalaya.com/live-web/v4/homepage?device=iPhone", method: .get, parameters: nil, encoding: URLEncoding.default, headers: nil).responseJSON { (response) in
if(response.error == nil){
print("请求成功")
// print(response.result.value as Any)
self.dicc = response.result.value as? NSDictionary
self.dictr = self.dicc?.object(forKey: "data") as! NSDictionary
self.dic1 = (self.dictr.object(forKey: "localRadios") as! NSArray)
// print(self.dic1 as Any)
self.table?.reloadData()
}else{
print("请求失败\(String(describing: response.error))")
}
//解析网址
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.dic1.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:newTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cells") as! newTableViewCell
table?.rowHeight = 120
let name:NSDictionary = dic1[indexPath.row] as! NSDictionary
let md:BaseModel = BaseModel()
md.dic = name
cell.setCellWithData(model: md)
cell.accessoryType = UITableViewCell.AccessoryType.detailDisclosureButton
return cell
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 {
return "ath.row] as! NSDictionary"
}else{
return "let name:NSDictionary nary"
}
}
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 30.0
}
}