Pull to refresh UITableView without UITableViewController

前端 未结 6 673
借酒劲吻你
借酒劲吻你 2020-11-29 15:11

I\'m trying to implement a pull to refresh feature in a UITableView within a UIViewController. I can\'t use a UITableViewController because I want the UITableView to be a sm

6条回答
  •  孤城傲影
    2020-11-29 15:56

    Objective-C:

    This is how you can implement pull to refresh for table view. Same as in the case of collection view. Just replace table view alloc with collection view.

    UITableView *tableViewDemo  =  [[UITableView alloc]init];
    tableViewDemo.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
    tableViewDemo.dataSource =  self;
    tableViewDemo.delegate =  self;
    [self.view addSubView: tableViewDemo];
    
    UIRefreshControl *refreshController = [[UIRefreshControl alloc] init];
    [refreshController addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
    [tableViewDemo addSubview:refreshController];
    
    #pragma mark - Handle Refresh Method
    
    -(void)handleRefresh : (id)sender
    {
       NSLog (@"Pull To Refresh Method Called");
       [refreshController endRefreshing];
    }
    

提交回复
热议问题