@interfaceViewController ()
//@property (nonatomic,strong) UITableView *myTableView;
@property (nonatomic,strong) UITableViewController *myTableViewController;
@end
@implementation ViewController
-(void)refreshView:(UIRefreshControl *)refresh {
refresh.attributedTitle = [[NSAttributedStringalloc] initWithString:@"Refreshing data..."];
// custom refresh logic would be placed here...
NSDateFormatter *formatter = [[NSDateFormatteralloc] init];
[formatter setDateFormat:@"MMM d, h:mm a"];
NSString *lastUpdated = [NSString stringWithFormat:@"Last updated on %@",
[formatter stringFromDate:[NSDate date]]];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:lastUpdated];
[refresh endRefreshing];
}
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
SEL refreshSEL = @selector(refreshView:);
/*
self.myTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
self.myTableView.delegate = self;
self.myTableView.dataSource = self;
[self.view addSubview:self.myTableView];
UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
[refresh addTarget:self action:refreshSEL forControlEvents:UIControlEventValueChanged];
[self.myTableView addSubview:refresh];
*/
self.myTableViewController = [[UITableViewControlleralloc] initWithStyle:UITableViewStylePlain];
self.myTableViewController.tableView.delegate = self;
self.myTableViewController.tableView.dataSource = self;
UIRefreshControl *refresh = [[UIRefreshControlalloc] init];
refresh.attributedTitle = [[NSAttributedStringalloc] initWithString:@"Pull to Refresh"];
[refresh addTarget:selfaction:refreshSEL forControlEvents:UIControlEventValueChanged];
self.myTableViewController.refreshControl = refresh;
[self.viewaddSubview:self.myTableViewController.tableView];
[selfaddChildViewController:self.myTableViewController];
}
Resource:
https://github.com/RbBtSn0w/RefreshControl