美文网首页
原生刷新和声明周期的注意点

原生刷新和声明周期的注意点

作者: BigBossZhu | 来源:发表于2016-11-08 08:12 被阅读16次

viewDidLoad方法和viewWillAppear

** homeConroller中tableView如果加在了viewDidLoad方法中,tableView底部无法去完全滑到.为什么怎么解决?? **

1. 首先学习了network调试方法执行顺序的功能,下方三个按钮取消系统的方法,和只显示多线程的作用,2. 发现了一个方法调用的顺序,viewDidLoad方法是在控制器创建的时候调用的,而viewWillApear方法是在makeKeyAndVisiable就是window显示以后才能显示View正确的frame,在viewDidLoad方法中设置的frame可能在后面会改变,所以无法滚到了.将frame设置在viewWillAppear中就可以了

原生的tableview刷新的实现

注意tip,让数据默默刷新,当将要显示到count-2时,就加载下拉刷新

 //refrechControl 
 lazy var refrechControl: UIRefreshControl = {
 let refrechControl = UIRefreshControl()
 refrechControl.addTarget(self, action: #selector(loadData), for: UIControlEvents.valueChanged)
 return refrechControl
 }()

 //bottomRefrech
 lazy var footRefrechActivity: UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
添加子视图
 tableView.addSubview(refrechControl) 
 //等于尾视图
 tableView.tableFooterView = footRefrechActivity

 //调用一个TableView的代理新方法,某个cell将要被显示时调用 
 func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
 if indexPath.row == 19 {
 //开始做下拉刷新的操作
 footRefrechActivity.startAnimating()
 loadData()
      }
 }

约束的bug

** lable的正文显示不全,后面显示...,解决:cell中的约束 **

  • 如果使用缓存行高,需要注释掉make.bootom.make的代码
  • 如果需要使用自适应代码就需要加上这句话.

相关文章

网友评论

      本文标题:原生刷新和声明周期的注意点

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