Swift iOS : 上拉刷新或者下拉刷新

栏目: Swift · 发布时间: 7年前

内容简介:Swift iOS : 上拉刷新或者下拉刷新

框架MJRefresh提供了上拉刷新或者下拉刷新,非常的喜闻乐见。

需要使用pod:

target 'Swift-MJrefresh' do
  use_frameworks!
  # Pods for Swift-MJrefresh
  pod 'MJRefresh'
end

记得去执行命令安装此框架:

pod install --verbose --no-repo-update

如下案例,演示此框架的使用过程:

import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window : UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        window = UIWindow()
        window!.rootViewController = Page()
        window!.rootViewController!.view.backgroundColor = .blue
        window!.makeKeyAndVisible()
        return true
    }
}
import MJRefresh
class Page: UIViewController ,UITableViewDataSource{
    var tableview: UITableView!
    let header = MJRefreshNormalHeader()
    let footer = MJRefreshAutoNormalFooter()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableview = UITableView()
        tableview.dataSource = self
        tableview.frame = view.frame
        self.view.addSubview(tableview)
        header.setRefreshingTarget(self, refreshingAction: Selector("headerRefresh"))
        self.tableview.mj_header = header
        footer.setRefreshingTarget(self, refreshingAction: Selector("footerRefresh"))
        self.tableview.mj_footer = footer
    }
    func headerRefresh(){
        print("下拉刷新")
        self.tableview.mj_header.endRefreshing()
    }
    var index = 0
    func footerRefresh(){
        print("上拉刷新")
        self.tableview.mj_footer.endRefreshing()
        // 2次后模拟没有更多数据
        index = index + 1
        if index > 2 {
            footer.endRefreshingWithNoMoreData()
        }
    }
    func numberOfSections(in: UITableView) -> Int {
        return 1;
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10;
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "a")
        cell.textLabel!.text = "测试刷新"
        return cell
    }
    func tableView(_ tableView: UITableView, heightForRowAtIndexPath indexPath: IndexPath) -> CGFloat {
        return 150;
    }
}

实验发现,即使是Obj-c写的框架,也只要:

import MJRefresh

而不再需要桥接文件(bridge.h)。以前都是需要的,为什么不需要了?还需要进一步查明。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Algorithmic Beauty of Plants

The Algorithmic Beauty of Plants

Przemyslaw Prusinkiewicz、Aristid Lindenmayer / Springer / 1996-4-18 / USD 99.00

Now available in an affordable softcover edition, this classic in Springer's acclaimed Virtual Laboratory series is the first comprehensive account of the computer simulation of plant development. 150......一起来看看 《The Algorithmic Beauty of Plants》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

在线进制转换器
在线进制转换器

各进制数互转换器

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具