没有 UITableViewController 的 UIRefreshControl [英] UIRefreshControl without UITableViewController

查看:22
本文介绍了没有 UITableViewController 的 UIRefreshControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是好奇,因为它似乎不可能立即实现,但是有没有一种偷偷摸摸的方法来利用新的 iOS 6 UIRefreshControl 类而不使用 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?

我经常使用带有 UITableView 子视图的 UIViewController 并符合 UITableViewDataSourceUITableViewDelegate 而不是使用UITableViewController 完全.

I often use a UIViewController with a UITableView subview and conform to UITableViewDataSource and UITableViewDelegate rather than using a UITableViewController outright.

推荐答案

凭直觉,基于 DrummerB 的灵感,我尝试简单地添加一个 UIRefreshControl 实例作为我的 UITableView 的子视图.它神奇地起作用了!

On a hunch, and based on DrummerB's inspiration, I tried simply adding a UIRefreshControl instance as a subview to my UITableView. And it magically just works!

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

这会在您的表格视图上方添加一个 UIRefreshControl 并按预期工作,而无需使用 UITableViewController :)

This adds a UIRefreshControl above your table view and works as expected without having to use a UITableViewController :)

以上仍然有效,但正如一些人指出的那样,以这种方式添加 UIRefreshControl 时会出现轻微的卡顿".一个解决方案是实例化一个 UITableViewController,然后将你的 UIRefreshControl 和 UITableView 设置为那个,即:

This above still works but as a few have pointed out, there is a slight "stutter" when adding the UIRefreshControl in this manner. A solution to that is to instantiate a UITableViewController, and then setting your UIRefreshControl and UITableView to that, i.e.:

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;

这篇关于没有 UITableViewController 的 UIRefreshControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆