本文翻译自:UIRefreshControl without UITableViewController

Just curious, as it doesn't immediately seem possible, but is there a sneaky way to leverage the new iOS 6 UIRefreshControl class without using a UITableViewController subclass? 只是好奇,因为它似乎不可能,但有没有一个偷偷摸摸的方式利用新的iOS 6 UIRefreshControl类而不使用UITableViewController子类?

I often use a UIViewController with a UITableView subview and conform to UITableViewDataSource and UITableViewDelegate rather than using a UITableViewController outright. 我经常使用带有UITableView子视图的UIViewController ,并且符合UITableViewDataSourceUITableViewDelegate而不是直接使用UITableViewController


#1楼

参考:https://stackoom.com/question/qRHg/没有UITableViewController的UIRefreshControl


#2楼

Well UIRefreshControl is a UIView subclass, so you can use it on it's own. 好的UIRefreshControl是一个UIView子类,所以你可以自己使用它。 I'm not sure though how it renders itself. 我不确定它是如何渲染自己的。 The rendering could simply depend on the frame, but it also could rely on a UIScrollView or the UITableViewController. 渲染可以简单地依赖于框架,但它也可以依赖于UIScrollView或UITableViewController。

Either way, it's going to be more of a hack than an elegant solution. 无论哪种方式,它都将是一个黑客而不是一个优雅的解决方案。 I recommend you look into one of the available 3rd party clones or write your own. 我建议您查看一个可用的第三方克隆或编写自己的克隆。

ODRefreshControl ODRefreshControl

SlimeRefresh SlimeRefresh


#3楼

On a hunch, and based on DrummerB's inspiration, I tried simply adding a UIRefreshControl instance as a subview to my UITableView . 在预感中,基于DrummerB的灵感,我尝试将UIRefreshControl实例作为子视图添加到我的UITableView And it magically just works! 它神奇地起作用!

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
[self.myTableView addSubview:refreshControl];

This adds a UIRefreshControl above your table view and works as expected without having to use a UITableViewController :) 这会在表视图上方添加一个UIRefreshControl并按预期工作,而不必使用UITableViewController :)


EDIT: This above still works but as a few have pointed out, there is a slight "stutter" when adding the UIRefreshControl in this manner. 编辑:上面这个仍然有效,但正如一些人所指出的那样,以这种方式添加UIRefreshControl时会有轻微的“口吃”。 A solution to that is to instantiate a UITableViewController, and then setting your UIRefreshControl and UITableView to that, ie: 解决方法是实例化UITableViewController,然后将UIRefreshControl和UITableView设置为,即:

UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = self.myTableView;self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(getConnections) forControlEvents:UIControlEventValueChanged];
tableViewController.refreshControl = self.refreshControl;

#4楼

What you would try is use container view inside ViewController you are using. 您将尝试使用您正在使用的ViewController中的容器视图。 you can define clean UITableViewController subclass with dedicated tableview and place that in the ViewController. 您可以使用专用的tableview定义干净的UITableViewController子类,并将其放在ViewController中。


#5楼

To eliminate the stutter that is caused by the accepted answer, you can assign your UITableView to a UITableViewController . 要消除由接受的答案引起的口吃,您可以将UITableView分配给UITableViewController

_tableViewController = [[UITableViewController alloc]initWithStyle:UITableViewStylePlain];
[self addChildViewController:_tableViewController];_tableViewController.refreshControl = [UIRefreshControl new];
[_tableViewController.refreshControl addTarget:self action:@selector(loadStream) forControlEvents:UIControlEventValueChanged];_theTableView = _tableViewController.tableView;

EDIT: 编辑:

A way to add a UIRefreshControl with no UITableViewController with no stutter and retain the nice animation after refreshing data on the tableview. 一种添加UIRefreshControl ,没有UITableViewController ,没有UIRefreshControl ,并在刷新tableview上的数据后保留好动画。

UIRefreshControl *refreshControl = [UIRefreshControl new];
[refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
[self.theTableView addSubview:refreshControl];
[self.theTableView sendSubviewToBack:refreshControl];

Later when handling the refreshed data... 稍后处理刷新数据时......

- (void)handleRefresh:(UIRefreshControl *)refreshControl {[self.theTableView reloadData];[self.theTableView layoutIfNeeded];[refreshControl endRefreshing];
}

#6楼

Try delaying the call to the refreshControl -endRefresh method by a fraction of a second after the tableView reloads its contents, either by using NSObject's -performSelector:withObject:afterDelay: or GCD's dispatch_after . 在tableView重新加载其内容之后, -performSelector:withObject:afterDelay:通过使用NSObject的-performSelector:withObject:afterDelay:或GCD的dispatch_after来延迟对refreshControl -endRefresh方法的调用,只需几分之一秒。

I created a category on UIRefreshControl for this: 我为此在UIRefreshControl上创建了一个类别:

@implementation UIRefreshControl (Delay)- (void)endRefreshingAfterDelay:(NSTimeInterval)delay {dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC));dispatch_after(popTime, dispatch_get_main_queue(), ^(void){[self endRefreshing];});
}@end

I tested it and this also works on Collection Views. 我测试了它,这也适用于集合视图。 I've noticed that a delay as small as 0.01 seconds is enough: 我注意到延迟小到0.01秒就足够了:

// My data refresh process here while the refresh control 'isRefreshing'
[self.tableView reloadData];
[self.refreshControl endRefreshingAfterDelay:.01];

没有UITableViewController的UIRefreshControl相关推荐

  1. UIRefreshControl使用总结

    2019独角兽企业重金招聘Python工程师标准>>> UIRefreshControl 的使用还是比较简单的,看一下 UIRefreshControl 的定义,基本就知道怎么用了. ...

  2. IOS6 新特性之UIRefreshControl

    "不会模仿的公司不是好公司不会剽窃的公司不是优秀公司  不会调戏代码的不是骨灰级码工 你同意吗? 苹果估计想取代第三方的pull to refresh"        ------ ...

  3. iOS - UIRefreshControl 刷新数据

    前言 NS_CLASS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED @interface UIRefreshControl : UIControl 1.UIRefresh ...

  4. UIRefreshControl

    1.使用范围 如果你装了xcode_4.5_developer_preview,那么在UITableViewController.h文件中你会看到,UITableViewController里面有如下 ...

  5. UIRefreshControl系统下拉刷新

    一直以来都是在用李明洁前辈封装的下拉刷新,最近看到有一个系统的下拉刷新,虽然用起来还有很多的限制,但是看到苹果的改变,还是值得肯定的,和大家分享一下.转载地址:http://blog.sina.com ...

  6. iOS开发之UIRefreshControl使用踩坑

    问题描述 接上一个话题,实现了TabBar的点击刷新以后,开始继续写完成功能,刷新UITableView,于是考虑到iOS 10以后,UIScrollView已经有UIRefreshControl的属 ...

  7. iOS - UIRefreshControl

    UIRefreshControl:UIControl (UIControl:UIView) 使用一: UITableView之Cell刷新,UIRefreshControl为其一属性. self.cu ...

  8. AFNetworking 3.0 源码解读(十)之 UIActivityIndicatorView/UIRefreshControl/UIImageView + AFNetworking...

    我们应该看到过很多类似这样的例子:某个控件拥有加载网络图片的能力.但这究竟是怎么做到的呢?看完这篇文章就明白了. 前言 这篇我们会介绍 AFNetworking 中的3个UIKit中的分类.UIAct ...

  9. UITableViewController

    UITableViewController 目录 概述 UITableView UITableViewCell 与UITableViewController相关的代理 UITableViewDataS ...

最新文章

  1. Ubuntu 16.04安装QQ(不一定成功)
  2. 华为南太无线解决方案部梁旭阳_工业互联网产业联盟网络组走进华为南京研究所技术研讨会顺利召开...
  3. 为什么 OLAP 需要列式存储
  4. 音频数据文件格式(PCM,WAV,MIDI)简记
  5. 高校竞赛排行榜主办方数据上传 操作手册
  6. Go安装web框架revel
  7. MongoDB数据库的创建与删除
  8. ELK学习5_ELK文档资料:《ELK stack 权威指南/饶琛琳》推荐
  9. 密钥方式登录linux,Linux的密钥对的方式登录方式
  10. python的回收机制_Python垃圾回收机制【人生苦短,我用python】-阿里云开发者社区...
  11. SQLSERVER:sqlserver2008r2安装好后,自动提示功能不可以使用
  12. java蓝桥杯算法训练 求1000以内的完数(题解)
  13. 审车按月还是日期_大额存单,应该选择按月付息还是到期一次性还本付息?
  14. python random 之基础点名器
  15. SpringCloud Greenwich版本集成OAuth2.0
  16. RFID应急物资管理系统
  17. 框架设计--第十章 MyBatis与Spring的整合--习题答案
  18. 防护器件TVS管基础知识
  19. 怎样在vue中使用jquery
  20. 港科百创 | “一清创新”完成新一轮融资,跻身准独角兽之列!

热门文章

  1. 《Android安全技术揭秘与防范》——第2章,第2.1节钱从哪里来
  2. 各种开源Android 系统定制
  3. 使用CXF 来发布一个 service
  4. SQL Server中,varchar和nvarchar如何选择
  5. fhq-treap模板
  6. SUSE Labs Con 2018有感
  7. 记百人计划--测试思路
  8. 【Spark】SparkStreaming-如何使用checkpoint
  9. backtrack5渗透 笔记
  10. 周报_2013第02周(2013/01/06-2013/01/12)