0

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");
}
Community
  • 1
  • 1
Alan
  • 796
  • 9
  • 26

2 Answers2

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;
Community
  • 1
  • 1
Alan
  • 796
  • 9
  • 26
0

You should instantiate your tableviewcontroller with

[UITableViewController alloc] initWithStyle:(UITableViewStyle)

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

Nicolas Manzini
  • 8,379
  • 6
  • 63
  • 81
  • That didn't help and actually then I UIRefreshController didn't show at all. The link I added above in my original post has a detailed discussion that explains why it has to be done the way I did it. Just my selector is ignored.... – Alan Nov 26 '13 at 11:25
  • Ok, I changed that but still my selector - (void)loadMoreData is not called. – Alan Nov 26 '13 at 11:41
  • i dont know. maybe try to make your refreshcontroller an instance variable and or check if it is nil at some point and you dont need to [self addChildViewController:_tableViewController]; // Not sure this is necessary – Nicolas Manzini Nov 26 '13 at 13:20
  • Yea I am quite stuck with this problem. Tried many different varieties but can get the selector called. Kinda feel I am missing something silly. – Alan Nov 26 '13 at 13:58