[求助]iOS调用reloadData()不刷新数据,不调用cellForRowAt方法
来源:互联网 发布:大数据彩票分析 编辑:程序博客网 时间:2024/06/11 10:02
代码如下:主线程调用了tableView的reloadData()之后只调用了numberOfRowsInSection,没有调用cellForRowAt一直找不到解决的方法还有出错的原因,希望有大神知道原因的能指点一下,感激不尽
import UIKitprotocol SearchViewDelegate { ///点击排序按钮调用 func searchView(clickSortBtn btn: UIButton) ///选中商品调用 func searchView(clickShopCell indexPath: IndexPath)}class SearchView: UIView, UITableViewDataSource, UITableViewDelegate { ///代理属性 var chDelegate: SearchViewDelegate? var snapBtn = UIButton() let btnTitles = ["相关", "销量", "价格", "新品"] var bottomLine = UIView() var shopTableV = UITableView() ///模型数组 var models: [SearchShopResultModel] = [] override init(frame: CGRect) { super.init(frame: frame) self.backgroundColor = UIColor.chBackGroundColor self.shopTableV.register(SearchViewShopCell.self, forCellReuseIdentifier: "searchShopCell") shopTableV.dataSource = self shopTableV.delegate = self } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } ///布局子视图 override func layoutSubviews() { ///1. 排序分类按钮 let btnBackV = UIView() btnBackV.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: 40) btnBackV.backgroundColor = UIColor.white self.addSubview(btnBackV) for i in 0..<btnTitles.count { let btn = UIButton.init(type: .custom) btn.setTitle(btnTitles[i], for: .normal) btn.setTitle(btnTitles[i], for: .highlighted) btn.setTitleColor(UIColor.gray, for: .normal) btn.setTitleColor(UIColor.red, for: .highlighted) btn.titleLabel?.font = UIFont.systemFont(ofSize: 13) btn.addTarget(self, action: #selector(typeBtnClick(btn:)), for: .touchUpInside) ///frame let btnW: CGFloat = self.frame.width / CGFloat(btnTitles.count) let btnH: CGFloat = btnBackV.frame.height let btnX: CGFloat = btnW * CGFloat(i) let btnY: CGFloat = btnBackV.frame.minY btn.frame = CGRect(x: btnX, y: btnY, width: btnW, height: btnH) btnBackV.addSubview(btn) if i == 0 { ///添加下划线 let bottomLine = UIView() bottomLine.backgroundColor = UIColor.red let lineX: CGFloat = btn.frame.minX + 10 let lineY: CGFloat = btn.frame.maxY - 2 let lineW: CGFloat = btn.frame.width - 20 let lineH: CGFloat = 2 bottomLine.frame = CGRect(x: lineX, y: lineY, width: lineW, height: lineH) btnBackV.addSubview(bottomLine) self.bottomLine = bottomLine ///发送点击事件 typeBtnClick(btn: btn) } } ///2. 搜索结果列表 let tableY: CGFloat = btnBackV.frame.maxY + 10 let tableX: CGFloat = 0 let tableW: CGFloat = UIScreen.screenWidth let tableH: CGFloat = UIScreen.screenHeight - tableY self.shopTableV.frame = CGRect(x: tableX, y: tableY, width: tableW, height: tableH) self.addSubview(shopTableV) } //MARK: - UITableViewDataSource func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return models.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = SearchViewShopCell.cellWithTable(tableView: tableView) let model = models[indexPath.row] cell.detailText = model.goodsName return cell } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 100 } //MARK: - UITableViewDelegate func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { print("点击了\(indexPath.row)") } ///点击事件 func typeBtnClick(btn: UIButton) { snapBtn.setTitleColor(UIColor.gray, for: .normal) btn.setTitleColor(UIColor.red, for: .normal) snapBtn = btn ///添加下划线 bottomLine.backgroundColor = UIColor.red let lineX: CGFloat = btn.frame.minX + 10 let lineY: CGFloat = btn.frame.maxY - 2 let lineW: CGFloat = btn.frame.width - 20 let lineH: CGFloat = 2 UIView.animate(withDuration: 0.2) { self.bottomLine.frame = CGRect(x: lineX, y: lineY, width: lineW, height: lineH) } } //MARK: - 外部方法 public func reloadView() { DispatchQueue.main.async { //刷新表格数据 self.shopTableV.reloadData() } }}
0 0
- [求助]iOS调用reloadData()不刷新数据,不调用cellForRowAt方法
- tableView调用reloadData不刷新, cellForRowAtIndexPath方法不走
- UITableView调用reloadData不刷新的Bug
- tableView调用reloadData不…
- tableView调用reloadData,数据没有刷新
- tableview cellForRowAtIndexPath reloadData不调用问题
- IOS cellForRowAtIndexPath方法不被调用
- iOS viewcontroller中的dealloc方法不调用
- iOS加载和刷新对象的那些方法(隐式调用),不完整求补充
- dealloc方法不调用
- GridPanel OnRefreshData PagingToolBar 不调用刷新方法的解决方法
- iOS -- 为什么viewDidAppear不调用?什么时候调用
- 客户端调用不刷新页面(Anthem)
- 怎么解决刷新不调用onbeforeunload
- jquery ajax调用不刷新页面
- BaseAdapter调用notifyDataSetChanged不刷新页面
- 调用notifyDataSetChanged之后listview不刷新
- listview调用notifyDataSetChanged()后不刷新界面
- Uva-489 Hangman Judge
- 从存储结构理解php空,null,0'0'false
- 1121 平面中的点 point类Ⅰ
- 把mysql的一些状态输出到文件里显示
- 【Android View绘制体系】requestLayout
- [求助]iOS调用reloadData()不刷新数据,不调用cellForRowAt方法
- 198. House Robber
- RCNN
- 浅入浅出TensorFlow 5
- Vue-component全局注册
- 《JavaScript高级语言设计》(第三版)学习笔记(1)
- 关于最大公约数算法的思考
- 史上最简单的SpringCloud教程 | 第十二篇: 断路器监控(Hystrix Dashboard)
- Python实现确认字符串是否包含指定字符串