1 Star 1 Fork 0

LuckyPia / NexusRefresh

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

NexusRefresh - iOS跨页面按需刷新

iOS Version Language Version License

背景

多页面数据关联,页面重新出现时都需要刷新,不需要刷新时也刷新,所以有很多无效请求。如果使用通知,通知是立即直接刷新,没有在页面出现时刷新,也有很多无效请求。如果当数据更改时,通知VC在出现时刷新,且只刷新一次,就好了。

NexusRefresh介绍

专注为页面刷新设计。当页面被通知需要刷新时,页面出现时才刷新(只刷新一次),而不是通知一次刷新一次。可以给页面添加多个标签,当该标签需要刷新时,所有含有该标签的页面都可以刷新。

安装

pod 'NexusRefresh', '2.0.4'

使用

  1. 定义刷新标签
import NexusRefresh

// MARK: 刷新标签扩展
extension NexusRefreshManager.Tag {
  /// 首页
  static let Home = NexusRefreshManager.Tag("Home")
   
}
  1. 监听刷新
class HomeViewController: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()
    // 将自己加入可刷新池
    NexusRefreshManager.shared.add(self, tags: [.Home]) {
        print("HomeViewController 刷新了")
    }
  }
}
  1. 通知刷新
// 调用
NexusRefreshManager.shared.refresh(tags: [.Home])

/// 刷新方法详情
/// - Parameters:
///  - tags: 标签列表
///  - filtObjects: 过滤列表
///  - force: 强制刷新,会直接刷新,不会等待出现(仅对VC有用)
public func refresh(tags: Set<Tag>, filtObjects: [AnyObject] = [], force: Bool = false)

Q&A

  1. 可以刷新除UIViewController以外的对象么? 可以,但是他们会在立即刷新,而不是出现时刷新

  2. 什么时候刷新? UIViewController若不在顶层,出现时刷新,在顶层,立即刷新。 非UIViewController立即刷新。

  3. 同一个对象可以多次添加刷新通知吗? 不可以,会以最后一次添加为准

  4. NotificationCenter异同

  • NotificationCenter在一个对象中可以有多个观察者。 NexusRefreshManager在一个对象中仅支持一个观察者。

  • NotificationCenter观察一个NotificationName。 NexusRefreshManager可以观察多个Tag。

  • NotificationCenter发送通知观察者立刻收到。 NexusRefreshManager如果不是强制刷新,未展示的UIViewController会在viewDidAppear时收到,且只会收到最后一次的通知。

  • NotificationCenter可以接受数据, NexusRefreshManager也可以接受数据。

更新日志

2.0.5

  1. 移除刷新时发送数据

2.0.4

  1. 降低RxSwift版本

2.0.3

  1. 优化代码

2.0.2

  1. 代码完善

2.0.1

  1. 单例支持

2.0.0

  1. 重构刷新管理器

1.0.2

  1. UIViewController增加NexusRefreshDelegate默认实现

1.0.1

  1. 增加错误提示
  2. 更新文档

Author

可以通过邮箱联系我: 664454335@qq.com

License

NexusRefresh is available under the MIT license. See the LICENSE file for more info.

Copyright (c) 2021 LuckyPia <664454335@qq.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
Swift 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/luckypia/NexusRefresh.git
git@gitee.com:luckypia/NexusRefresh.git
luckypia
NexusRefresh
NexusRefresh
master

搜索帮助