本文介绍了没有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?

我经常使用 UIViewController UITableView 子视图并符合 UITableViewDataSource UITableViewDelegate 而不是使用 UITableViewController outright。

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 00:46