itjhdev / itjh Goto Github PK
View Code? Open in Web Editor NEWIT江湖iOS客户端
IT江湖iOS客户端
现在上拉数据后,当前的cell位置不变
itjh的服务器挂了吗?APP都没法访问,,╮(╯▽╰)╭
非常感谢作者贡献开源源码,整体写的非常不错,但是在测试过程中发现IT江湖swift客户端源码,有一个重要线程更新问题。
以:HomeViewController.swift 文件的下拉刷新为例,其他都是一样的道理:
// MARK: 下拉刷新数据
func loadNewData(){
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
// 1.添加假数据
self.PAGE_NUM = 0
loadData(self.PAGE_NUM, size: SHOW_NUM, from:"header")
//
// 问题代码就在下面的异步更新里面,其实想法是2秒后 tablereload,但是你要知道,经常情况下是2秒数据还没有处理,也就出现了,2秒后tablereload,没有数据的情况,目前我看官方在苹果上架的app上也出现这个情况。
//
// 2.模拟2秒后刷新表格UI(真实开发中,可以移除这段gcd代码)
let delayInSeconds:Int64 = 1000000000 * 2
var popTime:dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW,delayInSeconds)
dispatch_after(popTime, dispatch_get_main_queue(), {
NSLog("异步刷新成功")
self.atableView.reloadData()
// 拿到当前的下拉刷新控件,结束刷新状态
self.atableView.header.endRefreshing()
self.atableView.footer.hidden = false
//结束网络活动指示器。
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
});
}
解决方法也很简单,把代码放到 loadData 的 Alamofire.request 的请求里面:
func loadData(offset:Int, size:Int ,from:String){
//接口url
var articleUrl = url + "page=\(offset)"
NSLog("上拉文章url地址:%@", articleUrl)
// 请求数据
Alamofire.request(.GET, articleUrl).responseJSON { (_, response, JSON_DATA, error) -> Void in
if JSON_DATA == nil{
SCLAlertView().showWarning("温馨提示", subTitle:"您的网络在开小差,赶紧制服它,精彩的文章在等你.", closeButtonTitle:"去制服")
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
return
}else{
if self.PAGE_NUM == 0{
if !self.currentArticleData.isEmpty{
self.currentArticleData.removeAll(keepCapacity: false)
}
}
let data = JSON(JSON_DATA!)
let articlesArray = data["content"].arrayValue
if articlesArray.count > 0{
NSLog("请求成功哦")
for currentArticle in articlesArray{
let article = Article()
article.aid = currentArticle["aid"].int!
article.title = currentArticle["title"].string!
article.date = currentArticle["date"].string!
article.img = currentArticle["img"].string!
article.author_id = currentArticle["author_id"].int!
article.author = currentArticle["author"].string!
self.currentArticleData.append(article)
}
//线程更新,by jincon。
dispatch_async(dispatch_get_main_queue()) {
self.atableView.reloadData()
if from == "header" {
// 拿到当前的下拉刷新控件,结束刷新状态
self.atableView.header.endRefreshing()
self.atableView.footer.hidden = false
}else{
self.atableView.footer.endRefreshing();
}
self.atableView.footer.endRefreshing();
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
}
//end
}else{
self.atableView.footer.noticeNoMoreData()
}
}
}
}
//by jincon
我想把iPhone版本改成ipad版本,但是文章分类只有“首页”,“技术”,“推文”,太少了,
'"http://m.itjh.com.cn:8080/mitjh/ArticleServer/queryArticleListByCategory/"
里面对应有8个分类?(我用curl一个个试过的)
这些分类对应的名称是?
好像服务器挂了?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.