MJRefresh无数据时让mj_footer显示在页面底部

2018-08-21  本文已影响1451人  姬歌

图中展示的视图为noDataView,添加方法是

tableView.addSubView(noDataView)

效果如下:


wrong.png

很明显这个效果太弱鸡,让人无法接受!mj_footer出现在了noDataView的上方!
现在,让我们做一些改进,不要直接在tableView上添加这个noDataView,而是把它当做一个section header来处理。

extension DCHistoryProjectViewController: UITableViewDataSource, UITableViewDelegate {
     //...
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if completedProjectArray.count == 0 {
            return noDataView.jk_h  //view的高度
        }
        return 0
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        if completedProjectArray.count == 0 {
            return noDataView
        }
        return nil
    }
}

现在,我们可以得到我们想要的效果了:


right.png

MJRefresh gitHub链接

上一篇下一篇

猜你喜欢

热点阅读