问题
I have a UIViewController that has a UITableView as a subview. I am trying to add a pull-to-refresh on the table.
Following some examples and discussions that I found here, I have the UIRefresh showing but it never calls the selector. I am not getting notified that the pull action happened.
I cannot use a UITableViewController as my main controller as I need to add a fixed button at the bottom of the screen.
I have the feeling I am missing something out that hopefully is obvious to someone else.
@interface ActivityViewController ()<UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate>
@end
- (void)viewDidLoad{
[super viewDidLoad];
_myTableView.delegate = self;
_myTableView.dataSource = self;
_tableViewController = [UITableViewController new];
_tableViewController.tableView = _myTableView;
[self addChildViewController:_tableViewController]; // Not sure this is necessary
_refreshControl = [UIRefreshControl new];
[_refreshControl addTarget:self action:@selector(loadMoreData) forControlEvents:UIControlEventValueChanged];
_tableViewController.refreshControl = _refreshControl;
}
- (void)loadMoreData{
NSLog(@"loadMoreData");
}
回答1:
Ok this is now working. But I am not sure why!! I kinda left it for a bit, changed other things that needed doing and then tested once more last night and it was working. I admit I am a bit confused. I used the code below from this answer given in earlier posts here as I did a few days ago. So thank you for the time and input. It works perfect now, as expected.
// Refresh control
UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = self.myTableView;
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(loadMoreData) forControlEvents:UIControlEventValueChanged];
tableViewController.refreshControl = self.refreshControl;
回答2:
You should instantiate your tableviewcontroller with
[UITableViewController alloc] initWithStyle:(UITableViewStyle)
using new
does an alloc init but you should use a designated initializer
来源:https://stackoverflow.com/questions/20214810/uirefreshcontrol-without-uitableviewcontroller-not-calling-selector