UIRefreshControl 下拉刷新

jopen 9年前發布 | 961 次閱讀 Objective-C IOS

- (void)viewDidLoad {
    [super viewDidLoad];

//UIRefreshControl
//系統自帶,繼承自UIControl,UIControl繼承自UIView
UIRefreshControl * refresh = [[UIRefreshControl alloc] init];
[self.tableView addSubview:refresh];

//設置標題
NSAttributedString * title = [[NSAttributedString alloc] initWithString:@"下拉刷新"];
refresh.attributedTitle = title;

//監聽什么時候開始下拉刷新
[refresh addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];


}

//監聽方法

  • (void)refresh:(UIRefreshControl *)refresh { NSLog(@"開始刷新"); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

      [NSThread sleepForTimeInterval:2];
      //回主線程刷新
       dispatch_sync(dispatch_get_main_queue(), ^{
    
           [refresh endRefreshing];
       });
    

    }); } </pre>

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!