在iOS 7中拉刷新
我正试图在我的表视图中使“拉入刷新”功能在iOS 7上正常工作。在viewDidLoad上,我有:在iOS 7中拉刷新,ios,ios7,pull-to-refresh,Ios,Ios7,Pull To Refresh,我正试图在我的表视图中使“拉入刷新”功能在iOS 7上正常工作。在viewDidLoad上,我有: self.refreshControl = [[UIRefreshControl alloc] init]; [self.refreshControl addTarget:self action:@selector(refreshInvoked:forState:) forControlEvents:UIControlEventValueChanged]; 然后我运行: -(void)
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上,这意味着当你在桌面视图上向下拉时,它会显示一个圆形箭头,当你拉的时候它会被拉长,拉得足够远后,它会刷新。但现在,我看不到圆形箭头,只看到UIActivityIndicator。它有时有效,有时无效。我缺少什么?您所说的“UIActivityIndicator”是UIRefreshControl的新默认外观
您向下拉,圆圈完成时,它显示您离触发刷新有多近。要在UITableView中添加UIRefreshControl…
- (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];
}
- (void)refresh:(UIRefreshControl *)refreshControl
{
[self refreshTableData]; //call function you want
[refreshControl endRefreshing];
}
1)在视图中加载..
- (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];
}
- (void)refresh:(UIRefreshControl *)refreshControl
{
[self refreshTableData]; //call function you want
[refreshControl endRefreshing];
}
2)调用相关方法刷新UITableView数据…
- (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];
}
- (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()
}
您可以删除/隐藏默认活动指示器,并添加自己的图像和动画 还有一个特定的阈值(距离),在调用刷新之前必须将表拉过该阈值 以下是我们的自定义拉刷新控件教程(在objective-c和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的默认属性,默认情况下为nil。如果需要,只需初始化refreshControl并分配它
let refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Please Wait..")
yourTableViewController.refreshControl = refreshControl
iOS 7中UIRefreshControl的默认外观是activityindicator。代码中也缺少此项:[self.myTableView addSubview:refreshControl];我看不出这在应用程序中有什么区别。尝试使用和不使用
[self.tableView addSubview:self.refreshControl]代码>并且没有看到任何更改@Nikos M.更详细的回答:谢谢,所以就我发布的代码而言,不需要更多了?(我意识到我遗漏了我为填充表而创建的实际刷新方法)。不,你可以走了。你可以改变它的颜色,但不幸的是,没有办法恢复到老的类似于柏忌的风格。你能告诉我,当我们释放它时,我们如何消除他或小延迟?