A
A
Antonnab2015-03-03 17:49:35
Swift
Antonnab, 2015-03-03 17:49:35

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()
        }
    }

Call the method for getting new elements and get data in it and update through beginUpdates - endUpdates, but again there is a disgusting twitching of the table.
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()

            }
            
        }
    }

If anyone has had this problem please tell me how you got rid of it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sashke, 2015-03-04
@Sashke

The twitching is due to insertRowsAtIndexPaths. If you do the usual [tableView reloadData] then everything will scroll smoothly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question