拉动刷新 (ios)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5133567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pull to Refresh (ios)
提问by jsttn
I recently implemented pull to refresh here: https://github.com/leah/PullToRefresh. It kind of works however it gets stuck with a spinning activity indicator. Their is also no text to the right of the arrow. What am I doing wrong? Thanks!
我最近在这里实现了 pull to refresh:https: //github.com/leah/PullToRefresh。它有点工作,但是它会被旋转的活动指示器卡住。他们的箭头右侧也没有文字。我究竟做错了什么?谢谢!
回答by Jonathan.
Without code there's not much anyone can say, but maybe try a different implementation of Pull To Refresh, like the enormego (EGO)version, the code is at github, here
没有代码,没有多少人可以说,但也许可以尝试不同的 Pull To Refresh 实现,比如enormego (EGO)版本,代码在github,here
It's used in the Facebook app so it definitely works.
它在 Facebook 应用程序中使用,所以它绝对有效。
回答by Claus
Apple has introduced UIRefreshControl in iOS6. You can integrate it in your UITableViewController using
Apple 在 iOS6 中引入了 UIRefreshControl。您可以使用将它集成到您的 UITableViewController 中
- (void)viewDidLoad {
[super viewDidLoad];
// Initialize Refresh Control
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
// Configure Refresh Control
[refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
// Configure View Controller
[self setRefreshControl:refreshControl];
}
the refresh: method will trigger the update and you can stop it in your API callback using:
refresh: 方法将触发更新,您可以使用以下命令在 API 回调中停止它:
[(UIRefreshControl *)sender endRefreshing];
回答by coolProgrammerTim
I am new to iOS development and I was trying to implement the pull to refresh in iOS 6. Well looking for a solution, I stumbled across this blog post and found it to be very helpful, http://www.intertech.com/Blog/Post/iOS-6-Pull-to-Refresh-(UIRefreshControl).aspx. It lays out the steps to implementing pull to refresh in a way that is easy to follow. Anyone looking to do this themselves in iOS 6 should check out the blog.
我是 iOS 开发的新手,我试图在 iOS 6 中实现 pull to refresh。很好地寻找解决方案,我偶然发现了这篇博文,发现它非常有帮助,http://www.intertech.com/博客/帖子/iOS-6-Pull-to-Refresh-(UIRefreshControl).aspx。它以易于遵循的方式列出了实施拉动刷新的步骤。任何想在 iOS 6 中自己做这件事的人都应该查看博客。
The UIRefreshControl is only useable with a Table View currently. There are a few steps to follow to successfully add a refresh control:
UIRefreshControl 当前仅可用于表视图。要成功添加刷新控件,需要遵循以下几个步骤:
1. Create a callback method to handle your refresh logic. The callback method should be invoked when a user pulls down on the table view. The signarture of the method should take one parameter: a pointer to the UIRefreshControl.
1. 创建一个回调方法来处理您的刷新逻辑。当用户下拉表格视图时,应调用回调方法。该方法的签名应采用一个参数:指向 UIRefreshControl 的指针。
Note: Steps 2-4 are all done within the Table View Controller's viewDidLoad method.
注意:步骤 2-4 都是在 Table View Controller 的 viewDidLoad 方法中完成的。
2. Instantiate the UIRefreshControl with a basic "alloc/init".
2. 使用基本的“alloc/init”实例化 UIRefreshControl。
3. Connect an action to the refresh control to invoke your callback method when the ValueChange event is fired.
3.连接一个动作刷新控制时ValueChange事件被触发调用回调方法。
4. Add the refresh control to the Table View Controller's "refreshControl" property.
4. 将刷新控件添加到表视图控制器的“refreshControl”属性中。
回答by Matt Connolly
I prefer the EGO implementation than the leah one because it does not require a subclass of your view controller. The original EGO one in github is a bit of a mess with no .gitnore file and lots of .DS_Store files added unnecessarily. Take a look at some of the many forks and pick one.
我更喜欢比利亚一个自我实现,因为它不需要您的视图控制器的子类。github 中的原始 EGO 有点混乱,没有 .gitnore 文件,并且不必要地添加了许多 .DS_Store 文件。看看许多叉子中的一些并选择一个。
The "emreberge" fork looks like a good version, better file organisation and documentation too!
“emreberge” fork 看起来是一个不错的版本,文件组织和文档也更好!
回答by Brian
I found this library very useful, fancy and up-to-date: https://github.com/Yalantis/Pull-to-Refresh.Rentals-iOS
我发现这个库非常有用、花哨和最新:https: //github.com/Yalantis/Pull-to-Refresh.Rentals-iOS
(Recommendations from other answers seem old and not maintained)
(其他答案的建议似乎过时且未维护)
回答by DannieCoderBoi
Now, with newer versions of iOS than the above stated iOS 5 you can use: UIRefreshControl.
现在,对于比上述 iOS 5 更新的 iOS 版本,您可以使用:UIRefreshControl。
There is a really good tutorial on creating your own custom pull to refresh for your iOS Application: http://ios-blog.co.uk/tutorials/how-to-add-a-custom-pull-to-refresh-in-your-ios-application/
有一个非常好的教程,可以为您的 iOS 应用程序创建自己的自定义拉取刷新:http: //ios-blog.co.uk/tutorials/how-to-add-a-custom-pull-to-refresh-in -你的ios应用程序/
回答by Anthony Blatner
Here's our tutorial on Custom Pull-to-Refresh controls, with code for Objective-C and Swift: http://www.Hymanrabbitmobile.com/design/ios-custom-pull-to-refresh-control/
这是我们关于自定义下拉刷新控件的教程,包含 Objective-C 和 Swift 的代码:http: //www.Hymanrabbitmobile.com/design/ios-custom-pull-to-refresh-control/
To add additional text or images, as you mentioned, add them into self.refreshLoadingView
in the setupRefreshControl
or scrollViewDidScroll
methods (from the tutorial).
要添加额外的文本或图像,如你所说,添加它们到self.refreshLoadingView
在setupRefreshControl
或scrollViewDidScroll
方法(从教程)。
Let me know if that helps!
如果这有帮助,请告诉我!
回答by Harry Tran
You can use : https://github.com/ngocbinh02/httablekit
您可以使用:https: //github.com/ngocbinh02/httablekit
Support iOS 5.0 or later
支持 iOS 5.0 或更高版本
Pull to refresh tableview
拉动刷新tableview
import <HTTableKit/TableKit>
....
//like UIRefreshControll
[tableview setPullToRefreshControlType:UITableViewRefreshControlTypeSystem];
[tableview setPullToRefreshModeEnable:YES beginHandler:^{
// to do here when pulling to refresh
}];
Dismiss pull to refresh tableview
关闭下拉刷新表视图
import <HTTableKit/TableKit>
....
[tableview dismissPullToRefreshEndHandler:^{
// to do here when dismissing
}];