美文网首页
Kingfisher 解析

Kingfisher 解析

作者: 三更夜半鬼仇天 | 来源:发表于2018-09-24 12:36 被阅读0次
    先注册
     table?.register(TableViewCell.self, forCellReuseIdentifier: "TableViewCellID")
            
    

    //MARK:数据请求
    func GETData() -> Void {
    let url = "https://www.zhaoapi.cn/data/content.json"

        Alamofire.request(url).responseJSON { (response) in
            //转化JSON
            let json = JSON(response.value!)
            //遍历data值
            for dict in json["data"].arrayValue{
                let dic = dict.dictionary ?? [:]
                let model:ViewModel = ViewModel()
                model.title = dic["title"]?.stringValue ?? ""
                model.desc = dic["desc"]?.stringValue ?? ""
                model.id = dic["id"]?.stringValue ?? ""
                
                
                
                
                for item in (dic["list"]?.arrayValue)!
                {
                    let ite = item.dictionary ?? [:]
                    let listmodel:listModel = listModel()
                    listmodel.id = ite["id"]?.stringValue ?? ""
                    listmodel.extension0 = ite["extension"]?.stringValue ?? ""
                    listmodel.definition = ite["definition "]?.stringValue ?? ""
                    listmodel.title = ite["title "]?.stringValue ?? ""
                    listmodel.connotation = ite["connotation "]?.stringValue ?? ""
                 //添加到 model
                    model.list.append(listmodel)
                }
                print(model.title)    
                //将model添加到数据
                self.dataArray.append(model)
            }
            //回到主线程刷新表格
            OperationQueue.main.addOperation({
                self.table?.reloadData()
            })
            
        }
    
    }
    

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCellID", for: indexPath) as! TableViewCell
    let model = dataArray[indexPath.row]
    cell.title.text = model.title
    // let url = URL(string:"https://www.zhaoapi.cn/images/unit/1.png" )
    //
    let url = URL(string: "https://www.zhaoapi.cn/images/unit/(model.id).png")

    // cell.icon.kf.setImage(with: url)

         cell.icon.kf.setImage(with: url, placeholder: UIImage(named: "1"), options: nil, progressBlock: nil, completionHandler: nil)
        return cell
    
    }
    

    相关文章

      网友评论

          本文标题:Kingfisher 解析

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