xcode 向 UIWebView iOS 添加下拉刷新功能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10871999/
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
Adding a pull to refresh feature to UIWebView iOS
提问by frddsgn
I'm looking to add a Pull to refresh feature to a UIWebView that I have in an app. I've used Pull to refresh in the past on table views, but I'm struggling to find any good tutorials/libraries to help me add it to UIWebViews specifically and this project.
我正在寻找向应用程序中的 UIWebView 添加拉动刷新功能。我过去曾使用 Pull 在表视图上刷新,但我正在努力寻找任何好的教程/库来帮助我将它专门添加到 UIWebViews 和这个项目。
I did get some of the way using PullToRefreshView by chpwn (https://github.com/chpwn/PullToRefreshView) but I can't get it detecting the drag. Does anyone know a better plug in/library?
我确实通过 chpwn ( https://github.com/chpwn/PullToRefreshView)获得了一些使用 PullToRefreshView 的方法,但我无法让它检测到拖动。有谁知道更好的插件/库?
回答by bitsdisasters
For me this post and code worked like a charm
对我来说,这篇文章和代码就像一个魅力
http://sonnyparlin.com/2011/12/pulltorefresh-ios-5-and-arc-tutorial/
http://sonnyparlin.com/2011/12/pulltorefresh-ios-5-and-arc-tutorial/
回答by Troy
I'm new to iOS development, so this may not be the best way… but it worked for me.
我是 iOS 开发的新手,所以这可能不是最好的方法……但它对我有用。
I took the controller that was wrapping my WebView and I changed it to a UITableViewController (it was just a UIViewController previously) so that I could take advantage of the refreshControl property of that controller (ios6 and up). I'm not making use of the TableView inside of the UITableViewController (though, it does seem to require one to exist, which I include, but I just don't populate it). I added 2 methods to the controller:
我拿了包装我的 WebView 的控制器,并将其更改为 UITableViewController(之前它只是一个 UIViewController),以便我可以利用该控制器(ios6 及更高版本)的 refreshControl 属性。我没有使用 UITableViewController 内部的 TableView(虽然,它似乎确实需要一个存在,我包括它,但我只是不填充它)。我向控制器添加了 2 个方法:
- (void)addPullToRefresh
{
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
[refreshControl addTarget:self.myWebView action:@selector(reload)
forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
}
- (void)stopRefresh
{
[self.refreshControl endRefreshing];
}
I put a call to [self addPullToRefresh]; in viewDidLoad, and I added a call to [self stopRefresh]; in webViewDidFinishLoad:
我打电话给 [self addPullToRefresh]; 在 viewDidLoad 中,我添加了对 [self stopRefresh] 的调用;在 webViewDidFinishLoad 中:
I got my instructions for how to use the refreshControl property of UITableViewController here.
我在此处获得了有关如何使用 UITableViewController 的 refreshControl 属性的说明。