objective-c - 没有 UITableViewController 的 UIRefresh

只是好奇,因为这似乎不可能立即实现,但是有没有一种偷偷摸摸的方法来利用新的 iOS 6 UIRefreshControl 类而不使用 UITableViewController 子类?

我经常使用带有 UITableView subview 的 UIViewController 并符合 UITableViewDataSourceUITableViewDelegate 而不是使用UITableViewController 彻底。

最佳答案

凭直觉,并根据 DrummerB 的灵感,我尝试简单地将 UIRefreshControl 实例作为 subview 添加到我的 UITableView 中。它神奇地起作用了!

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

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


编辑:上面仍然有效,但正如一些人指出的那样,以这种方式添加 UIRefreshControl 时会出现轻微的“口吃”。一个解决方案是实例化一个 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;

关于objective-c - 没有 UITableViewController 的 UIRefreshControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12497940/

相关文章:

ios - 为什么苹果推荐使用 dispatch_once 来实现 ARC 下的单例模式?

ios - 如何在 NSLog 中打印 bool 标志?

objective-c - NSDate 获取年/月/日

ios - UITableView 单元格选择颜色?

objective-c - Objective-C中强弱的区别

objective-c - 如何为 NSDate 添加 1 天?

ios - 如何使用 NSURLConnection 与 SSL 连接以获得不受信任的证书?

iphone - 如何检测 iPhone 5(宽屏设备)?

ios - UIImageView 在设备上的启动屏幕中缺少图像

objective-c - 如何将堆栈跟踪打印到控制台/登录 Cocoa?