[iOS]知乎日报第二周总结-后端皇帝zwm说:那怎么办?
文章目录
小结
开始写的第八天
这八天内还是没写多少 控制不了拖延症 我直接泪目
完成了知乎日报主页
了解了WKWebView的一些简单的使用
实现WebView内的无限滑动刷新
知乎日报主页的无限刷新
到底什么时候请求数据并刷新
其实上周讲过了 但是我小改了一点
顺便水一下字数吧
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat contentHeight = scrollView.contentSize.height;
CGFloat scrollViewHeight = self.view.frame.size.height;
if (offsetY < 0) {
scrollView.contentOffset = CGPointMake(0, 0);
[self.activityIndicator startAnimating];
[self loadnewsModel];
}
if (offsetY > contentHeight - scrollViewHeight) {
// 当滚动到底部时,加载更多数据
[self loadMoreData];
}
}
刷新出来的数据怎么处理
通过设置一个字典 并用日期为key值来存储以往每天的数据是个很不错的方法
起码对我来说省力很多
self.newsModel = [[NewsModel alloc] initWithData:data error:nil];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];//获取日期
[dateFormatter setDateFormat:@"yyyyMMdd"];
NSTimeInterval days = -24 * 60 * 60;
NSDate *daysEarlier = [self.currentDate dateByAddingTimeInterval:-days];
NSString *dateStr = [dateFormatter stringFromDate:daysEarlier];
//NSLog(@"%@", dateStr);
self.dataDictionary = [[NSMutableDictionary alloc] init];
[self.dataDictionary setValue:self.newsModel forKey:dateStr];
dispatch_async(dispatch_get_main_queue(), ^{
self.tableView reloadData];
[self.activityIndicator stopAnimating];
}
UIScrollView与子View的触摸事件冲突
就是 tableView 也是一个 scrollView 的子类
然后我的 scrollView 把tableView 的整个 cell 给填满了
就触发不了 cell 的点击事件了
借用我们后端皇帝zwm的口头禅 :那怎么办?男的女的?
比较简单的方法就是设置手势事件
当然 也可以取消 scrollView 的触发事件
当然 后一种显然不符合我们的本意
毕竟咱们还是比较喜欢这个无限滚动视图的
看看手势事件
添加点按击手势监听器
//添加点按击手势监听器
UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapUiscrollView)];
//设置手势属性
tapGesture.delegate = self;
tapGesture.numberOfTapsRequired = 1;//设置点按次数,默认为1,注意在iOS中很少用双击操作
tapGesture.numberOfTouchesRequired = 1;//点按的手指数
[cell.scrollView addGestureRecognizer:tapGesture];
设置滚动视图的手势事件
- (void)tapUiscrollView {//设置滚动视图的手势事件
CGFloat contentX = [[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] scrollView].contentOffset.x / self.view.bounds.size.width;
double x = contentX;
int i = x;
self.webView = [[WebViewController alloc] init];
self.webView.x = i - 1;
self.webView.urlArray = self.top_stroiesURLArray;
[self.navigationController pushViewController:self.webView animated:YES];
}
WebView部分怎么实现呀
webView的简单使用方法
我也不知道
先导入 WebKit/WebKit.h 库
#import <WebKit/WebKit.h>
然后向view上添加你的WebView
WKWebView* webView = [[WKWebView alloc]init];
webView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
[view addSubview:webView];
NSURL* urlTest = [NSURL URLWithString:urlStr];
NSURLRequest* requestTest = [NSURLRequest requestWithURL:urlTest];
[webView loadRequest:requestTest];
没了 就这么多 你加油
怎么让你的webView可以左右滑动而且一直滑动
一次性把所有的界面都加载出来是一种方法 但是太麻烦了
有没有简单一点的?
又想起来了我们亲爱的无限轮播视图
确实 只需要左中右三个视图
滑动时 更新一个新的界面 就可以无限滑动啦
这个就不贴代码了
相关内容比较多 也没啥意义