0

在我的 iPhone 应用程序中,我使用 Web 视图来显示用户提要。为了刷新,我在用户从顶部向上滚动时发送服务器请求。我想为此使用一些很酷的提神剂。

我试过ODRefresh控制器(Git- here),但它只适用于滚动视图和表格视图,而不适用于UIWebVIew(和应用程序崩溃)。我已经UIScrollView使用方法实现了对 webview 的委托addScrollViewListener,但我仍然没有运气。

我的代码如下:

- (void)viewDidLoad
{
    [super viewDidLoad];

    ODRefreshControl *refreshControl = [[ODRefreshControl alloc] initInScrollView:self.myWebView];
    [refreshControl addTarget:self action:@selector(dropViewDidBeginRefreshing:) forControlEvents:UIControlEventValueChanged];
}

- (void)dropViewDidBeginRefreshing:(ODRefreshControl *)refreshControl
{
    double delayInSeconds = 3.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [refreshControl endRefreshing];
    });
}

- (void) addScrollViewListener
{
    UIScrollView* currentScrollView;
    for (UIView* subView in myWebView.subviews) {
        if ([subView isKindOfClass:[UIScrollView class]]) {
            currentScrollView = (UIScrollView*)subView;
            currentScrollView.delegate = self;
        }
    }
}
4

1 回答 1

0
ODRefreshControl *refreshControl = [[ODRefreshControl alloc] initInScrollView:[[self.myWebView subviews] objectAtIndex:0]];

或者

ODRefreshControl *refreshControl = [[ODRefreshControl alloc] initInScrollView:[[self.myWebView subviews]lastObject]];
于 2013-01-25T07:06:54.087 回答