Answer the question
In order to leave comments, you need to log in
How to load a UITableViewCell into a table?
Good afternoon! I struggle with the possibility of organizing the loading of table cells in UITableViewCell. It is necessary to make close to the application Zuckerberg Call.
I tried to use the SVPullToRefresh library - in the image and likeness of jslim.net/blog/2014/04/01/infinite-scroll-using-on... (well, only in Swift), but when added, the entire table literally twitches.
I tried to add in the method
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if(indexPath.row == self.currentPage * 10 - 3){
self.getNextNews()
}
}
func getNextNews(){
Alamofire.request(.GET, urlQuery, parameters: ["universityId": UBUniversitySettings.getUniversityId(), "page" : currentPage, "pageSize" : 10]).responseJSON{ (request, response, JSON, error) in
println(JSON)
var newsResponse = JSON! as NSArray
if(newsResponse.count > 0){
var newsIndex:NSInteger = 0
var paths:NSMutableArray = NSMutableArray()
for newsItemResponse in newsResponse{
var newsItem:NewsModel = NewsModel()
newsItem.newsImage = newsItemResponse.valueForKey("previewPic") as? String
newsItem.newsTitle = newsItemResponse.valueForKey("title") as? String
newsItem.newsDescription = newsItemResponse["content"] as? String
newsItem.newsId = newsItemResponse["id"] as? String
newsItem.newsDate = NSDate(timeIntervalSince1970: newsItemResponse["createDate"] as Double/1000)
self.tableViewNews.addObject(newsItem)
var indexPathVal = self.currentPage * 10 + newsIndex
var indexPath = NSIndexPath(forRow: indexPathVal as Int, inSection: 0)
paths.addObject(indexPath)
newsIndex = newsIndex + 1
}
self.newsTableView.beginUpdates()
self.newsTableView.insertRowsAtIndexPaths(paths, withRowAnimation: UITableViewRowAnimation.Left)
self.currentPage = self.currentPage + 1
self.newsTableView.endUpdates()
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question