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)。以前都是需要的,为什么不需要了?还需要进一步查明。


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

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

人工智能+:AI与IA如何重塑未来

人工智能+:AI与IA如何重塑未来

[美]韩德尔·琼斯(Handel Jones) [中]张臣雄 / 机械工业出版社 / 2018-10 / 55.00

当深度学习模型引发了全世界对人工智能的再次关注时,人工智能迎来第三次高速增长,人工智能(AI)、增强现实(AR)和虚拟现实(VR)正把人类带向新的“智能增强时代”(IA),我们将在不知不觉中接纳机器智能。 针对人类社会长期存在的众多复杂的动态的难题,人机融合智能将会提供全新的解决方案,谷歌、Facebook、微软、亚马逊、腾讯、阿里巴巴、百度等平台巨头纷纷斥千亿巨资布局人工智能的尖端技术;智......一起来看看 《人工智能+:AI与IA如何重塑未来》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具