美文网首页
快速创建Swift的TableView

快速创建Swift的TableView

作者: 久仰_1d3e | 来源:发表于2022-10-11 17:43 被阅读0次

1. 创建

lazy var tableView : UITableView = {

        lettableView =UITableView.init(frame:.zero,style:UITableView.Style.plain)

        tableView.separatorStyle = UITableViewCell.SeparatorStyle.singleLine

        tableView.backgroundColor="F3F6F9".uicolor()

        tableView.separatorInset=UIEdgeInsets.init(top:0,left:0,bottom:0,right:0)

        tableView.estimatedRowHeight=0

        tableView.estimatedSectionFooterHeight = 0

        tableView.estimatedSectionHeaderHeight = 0

        tableView.dataSource=self

        tableView.delegate=self

        tableView.register(MyCell.self, forCellReuseIdentifier: "mycell")

        tableView.tableFooterView=UIView()

        // 下拉刷新

        tableView.es.addPullToRefresh(animator: header, handler: {

            [unownedself]in

            self.headerRereshing()

        });

        // 上拉加载

        tableView.es.addInfiniteScrolling(animator: footer) {

            [unownedself]in

            self.footerRereshing()

        }

        returntableView

    }()

2.事件

  /// 下拉刷新

    func headerRereshing() {

        UIView .performWithoutAnimation {

            self.tableView.es.stopPullToRefresh()

        }

    }

    ///上拉加载

    func footerRereshing() {

        UIView.performWithoutAnimation {

            self.tableView.es.stopLoadingMore()

        }

    }

extension ViewController: UITableViewDelegate,UITableViewDataSource {

    functableView(_tableView:UITableView,numberOfRowsInSectionsection:Int) ->Int{

        return 8

    }

    functableView(_tableView:UITableView,cellForRowAtindexPath:IndexPath) ->UITableViewCell{

        let cell:MyTableViewCell! = tableView.dequeueReusableCell(withIdentifier: "mycell",for: indexPath) as?MyTableViewCell

        returncell

    }

    functableView(_tableView:UITableView,heightForRowAtindexPath:IndexPath) ->CGFloat{

        return156.0

    }

}

class MyTableViewCell: UITableViewCell {

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {

        super.init(style: .default,reuseIdentifier: reuseIdentifier)

        self.selectionStyle = UITableViewCell.SelectionStyle.none

           }

    requiredinit?(coder:NSCoder) {

        fatalError("init(coder:) has not been implemented")

    }

}

相关文章

网友评论

      本文标题:快速创建Swift的TableView

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