문제

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");
}
도움이 되었습니까?

해결책

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;

다른 팁

You should instantiate your tableviewcontroller with

[UITableViewController alloc] initWithStyle:(UITableViewStyle)

using new does an alloc init but you should use a designated initializer

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top