如何将刷新控件应用于UITableView

时间:2015-07-03 09:02:01

标签: ios objective-c

有没有办法将刷新控件应用于UITableView中设置的UIViewController

我找到的解决方案需要UITableViewController的子类化,这对我来说很麻烦,因为我需要子类UIViewController而不是UITableViewController,我没有看到任何方法UITableView的文档,允许我对其设置刷新控件。

非常感谢任何帮助!

3 个答案:

答案 0 :(得分:9)

使用此UIRefreshControl控件:

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refresh1:) forControlEvents:UIControlEventValueChanged];
[Delivered_TBL addSubview:refreshControl];


- (void)refresh1:(UIRefreshControl *)refreshControl
{
    [self Service_Call];
    [refreshControl endRefreshing];
}

答案 1 :(得分:2)

答案 2 :(得分:2)

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.backgroundColor = [UIColor clearColor];
refreshControl.tintColor = [UIColor whiteColor];
[refreshControl addTarget:self
                   action:@selector(getLatestData)
         forControlEvents:UIControlEventValueChanged];

[yourTableviewName addSubview:refreshControl];


   -(void)getLatestData
{
 // here add your reload method
  [self XXXXX]; 

  NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  [formatter setDateFormat:@"MMM d, h:mm a"];
   NSString *title = [NSString stringWithFormat:@"Last update: %@", [formatter stringFromDate:[NSDate date]]];
   NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor]
                                                                    forKey:NSForegroundColorAttributeName];
   NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrsDictionary];
        refreshControl.attributedTitle = attributedTitle;

        [refreshControl endRefreshing];
    }