我正在使用 SwipeView 库来创建一系列可滑动的 webview ( https://github.com/nicklockwood/SwipeView )。
来回滑动几次后,webviews 显示乱序,有时重复(位置 1 的项目与位置 3 的项目重复,等等)
github(https://github.com/nicklockwood/SwipeView/issues/40)上有一个类似的问题,但我认为我正确设置了重用视图。
- (UIView *)swipeView:(SwipeView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
UIWebView *webView = (UIWebView *) view;
if (webView == nil) {
webView = [[UIWebView alloc] initWithFrame:swipeView.frame];
UIRefreshControl *rControl = [[UIRefreshControl alloc] init];
[rControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
[webView.scrollView addSubview:rControl];
}
webView.delegate = self;
NSString *strURL = _urls[index];
NSURL *url = [NSURL URLWithString:strURL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];
return webView;
}
来自调试器:(注意 _itemViews 是如何出现故障的)
_itemViews __NSDictionaryM * 4 key/value pairs 0x08e5ce20
[0] (null) (int)0 : (no summary)
[1] (null) (int)3 : (no summary)
[2] (null) (int)1 : (no summary)
[3] (null) (int)2 : (no summary)
_urls __NSArrayM * @"4 objects" 0x14d9ca00
[0] __NSCFConstantString * @"http://cmcewen.ngrok.com/links/new" 0x000eac50
[1] __NSCFConstantString * @"http://cmcewen.ngrok.com/users/sign_in" 0x000eac60
[2] __NSCFString * @"http://cmcewen.ngrok.com/links/178" 0x14e49630
[3] __NSCFString * @"http://cmcewen.ngrok.com/links/178/comments" 0x14e4d510