我正在尝试在我的应用程序中实现下拉刷新功能。该架构是这样的,即 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/