美文网首页
2020-08-11

2020-08-11

作者: iOSWater | 来源:发表于2020-08-11 14:19 被阅读0次
        lazy var tableView: UITableView = {
            let tempView = UITableView()
            tempView.backgroundColor = .white
            tempView.delegate = self
            tempView.dataSource = self
            tempView.register(UINib.init(nibName: "MyAssetQianBaoTableViewCell", bundle: nil), forCellReuseIdentifier: cellID)
            tempView.separatorStyle = .none
            tempView.mj_header = RefreshUtil.createRefreshHeader(viewContorl: self, selector: #selector(refresh))
            return tempView
        }()
    
    typealias CellSelectModel = (AssetWalletDataModel)->()
    
    class MyAssetBottomListViewController: UIViewController {
    
        let cellID = "REUSEDCELLID"
        var cellArr: [AssetWalletDataModel] = []
    
        var cellSeletcModelBlock:CellSelectModel?
    }
    
    extension MyAssetBottomListViewController:UITableViewDelegate,UITableViewDataSource{
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return cellArr.count
        }
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell:MyAssetQianBaoTableViewCell = tableView.dequeueReusableCell(withIdentifier: cellID) as! MyAssetQianBaoTableViewCell
            cell.selectionStyle = .none
            cell.model = cellArr[indexPath.row]
            return cell
        }
        
        func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
            return 90
        }
        func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            let model = cellArr[indexPath.row]
            if cellSeletcModelBlock != nil {
                cellSeletcModelBlock!(model)
            }
        }
    }
    
    
    extension MyAssetBottomListViewController{
        
        @objc func refresh() {
            if GlobalArea.share.isLogin{
                getServerData()
            }
        }
        func getServerData() {
            let parameters: [String : Any] = [
                "data" : ["coinType": "","isHide" : "0"],
                "pageNo" : 1,
                "pageSize" : 99999
            ]
            Networks.postJSON(CallUtil.tradingWalletIndexUrl, serverType: .wallet, parameters: parameters).then { [weak self] (body) in
                guard let strongSelf = self else {return}
                strongSelf.tableView.mj_header.endRefreshing()
                let jsonString = String(data: body, encoding: String.Encoding.utf8)
                let model = AssetWalletModel.deserialize(from: jsonString)
                if model?.code == 0 {
                    strongSelf.cellArr = model?.result?.list ?? []
                    DispatchQueue.main.async { [weak self] in
                        guard let strongSelf = self else {return}
                        strongSelf.tableView.reloadData()
                    }
                }
            }.catch { (error) in
                self.tableView.mj_header.endRefreshing()
                IndiView.showMsg(message: error.localizedDescription)
            }
        }
    }
    
                    DispatchQueue.main.async { [weak self] in
                        guard let strongSelf = self else {
                            return
                        }
                        strongSelf.bbtableView.reloadData()
                    }
    

    相关文章

      网友评论

          本文标题:2020-08-11

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