拉到iOS 7中刷新

我试图让我的表视图中的iOS 7上正常工作的刷新function。 在viewDidLoad上,我有:

self.refreshControl = [[UIRefreshControl alloc] init]; [self.refreshControl addTarget:self action:@selector(refreshInvoked:forState:) forControlEvents:UIControlEventValueChanged]; 

然后我运行:

 -(void) refreshInvoked:(id)sender forState:(UIControlState)state { // Refresh table here... [_allEntries removeAllObjects]; [self.tableView reloadData]; [self refresh]; } 

当刷新方法调用的请求完成时,在didCompleteRequest代码中,我有:

 [self.refreshControl endRefreshing]; 

在iOS 6上,这意味着当你拉下桌子的时候,它会显示一个圆形的箭头,当你拉动的时候会拉长,拉到足够的时候,它会刷新。 现在,我看不到任何圆形的箭头,只是一个UIActivityIndi​​cator。 它也有时会工作,有时不会。 我错过了什么?

你所说的“UIActivityIndi​​cator”是UIRefreshControl的新的默认外观。

你拉下来,随着圆圈的完成,它显示了触发刷新的距离。

在UITableView中添加UIRefreshControl …

1)在ViewDidLoad ..

 - (void)viewDidLoad { [super viewDidLoad]; //to add the UIRefreshControl to UIView UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Please Wait..."]; //to give the attributedTitle [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged]; [tblVideoView addSubview:refreshControl]; } 

2)调用相关的方法来刷新UITableView数据…

 - (void)refresh:(UIRefreshControl *)refreshControl { [self refreshTableData]; //call function you want [refreshControl endRefreshing]; } 

或Swift

  let refreshControl : UIRefreshControl = UIRefreshControl.init() refreshControl.attributedTitle = NSAttributedString.init(string: "Please Wait...") refreshControl.addTarget(self, action: #selector(refresh), forControlEvents: UIControlEvents.ValueChanged) feedTable.addSubview(refreshControl) func refresh(refreshControl:UIRefreshControl){ self.refreshTableData()//call function you want refreshControl.endRefreshing() } 

您可以删除/隐藏默认的活动指示器,并添加自己的图像和animation。

还有一个特定的阈值(距离),该表必须在调用刷新之前被拉过。

这里是我们的自定义拉到刷新控件教程(在Objective-C和Swift中): http : //www.jackrabbitmobile.com/design/ios-custom-pull-to-refresh-control/

希望它有帮助,让我知道,如果我可以回答其他任何事情

更新为swift

对于TableView

  - (void)viewDidLoad { let refreshControl = UIRefreshControl() refreshControl.attributedTitle = NSAttributedString(string: "Please Wait..") tableView.addSubview(refreshControl) refreshControl.addTarget(self, action: #selector(refreshTable), forControlEvents: UIControlEventValueChanged) } - (void)refreshTable { //Refresh Data here //...... //Once all the data is fetched. If you are loading asynchronously add the below code inside the async block refreshControl.endRefreshing() [tableView reloadData]; } 

对于UITableViewController

在UITableViewController中有一个名为refreshControl的默认属性,默认为零。 如果你只想初始化refreshControl并分配它。

 let refreshControl = UIRefreshControl() refreshControl.attributedTitle = NSAttributedString(string: "Please Wait..") yourTableViewController.refreshControl = refreshControl