只是好奇,因为这似乎不可能立即实现,但是有没有一种偷偷摸摸的方法来利用新的 iOS 6 UIRefreshControl
类而不使用 UITableViewController
子类?
我经常使用带有 UITableView
subview 的 UIViewController
并符合 UITableViewDataSource
和 UITableViewDelegate
而不是使用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/