簡體   English   中英

如何將刷新控制應用於 UITableView

[英]How To Apply Refresh Control To UITableView

有沒有辦法將刷新控件應用於UIViewController設置的UITableView

我找到的解決方案需要UITableViewController子類化,這對我來說很麻煩,因為我需要將UIViewController子類化而不是UITableViewController ,而且我在UITableView的文檔下沒有看到任何允許我設置刷新控件的方法。

任何幫助將不勝感激!

使用此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];
}
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];
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM