ios - 在 UIViewController 内部的 UITableView 上拉动刷新

标签 ios uitableview pull-to-refresh uirefreshcontrol

我正在尝试在我的应用程序中实现下拉刷新功能。该架构是这样的,即 UIViewController 中有一个 UITableView。我希望能够在下拉时刷新 tableview。我在 viewDidLoad 方法中尝试了下面的代码,但它不起作用。任何人都可以告诉我我在实现中哪里错了吗?

UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
    refresh.tintColor = [UIColor grayColor];
    refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
    [refresh addTarget:self action:@selector(get_vrns) forControlEvents:UIControlEventValueChanged];
    [self.vrnTable addSubview:refresh];

最佳答案

由于您不能使用 UITableViewController 代替 UIViewController,请尝试这样做:

UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = self.vrnTable;

UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
refresh.tintColor = [UIColor grayColor];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
[self.refresh addTarget:self action:@selector(get_vrns) forControlEvents:UIControlEventValueChanged];

tableViewController.refreshControl = self.refresh;

希望这对您有所帮助!

关于ios - 在 UIViewController 内部的 UITableView 上拉动刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20138698/

相关文章:

iphone - 将 CLLocation 或 CLLocationCoordinate2D 转换为 CGPoint

iphone - 通过按下按钮在 map 上放置图钉——iOS

ios - 如何检查在 NSData 中转换的媒体类型

ios - 设置uitableview背景 View

ios - 如何在 iOS 中创建多行表格单元格?

android - https ://github. com/chrisbanes/ActionBar-PullToRefresh 从服务器拉取

ios - Swift:UITextField IBAction - EditingChanged - 按钮保持启用状态,即使文本字段值已更改?

ios - Swift 2 - sharedInstance 函数返回 nil

ios - 拉动刷新没有 UITableViewController 的 UITableView 不工作

ios - 在Tableview Pull中使用QBSimpleSyncRefreshControl刷新时应用崩溃