- 構建類型的新聞源
問題
- 我需要加載更多帖子動作當用戶滾動到最後一個表格單元格
- 我不知道從哪裏開始,如何實施,凡在代碼
- 所以基本上我需要打電話到服務器,下載的帖子時,用戶滾動到最後一個表視圖,追加的職位,以目前的表視圖 底部
下面是相關的代碼塊(我想!)
class GeneralPostAreaController: UIViewController {
...
extension GeneralPostAreaController: UITableViewDataSource {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return PostsCollection.postsFromParse.posts.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("PostCell") as! PostTableViewCell
cell.postImage.image = PostsCollection.postsFromParse.posts[indexPath.row].image
cell.postName.text = PostsCollection.postsFromParse.posts[indexPath.row].name
cell.postText.text = PostsCollection.postsFromParse.posts[indexPath.row].text
cell.loadAudio = PostsCollection.postsFromParse.posts[indexPath.row].audioObject.parseAudioData
return cell
}
}
這裏是我使用從服務器(解析)獲取數據的代碼。原諒可怕的數據結構,這是我的第一個應用程序!
class ParseQueryer: NSObject{
//HAVE TO RESTRUCTURE
var posts: [Post] = []
//this is not a very elegant way to reload table Data
func getPosts(selectedTableView: UITableView){
var query = PFQuery(className: "Post")
query.addDescendingOrder("createdAt")
query.limit = 10
query.findObjectsInBackgroundWithBlock {(result: [AnyObject]?, error: NSError?) -> Void in
self.posts = result as? [Post] ?? []
selectedTableView.reloadData()
for post in self.posts{
post.name = post["Name"] as? String
post.text = post["Text"] as? String
//println(post.text)
if let audioData = post["Audio"] as? PFFile {
audioData.getDataInBackgroundWithBlock({
(audioData: NSData?, error: NSError?) -> Void in
if (error == nil){
post.audioObject.parseAudioData = audioData
}
})
}
if let imgData = post["Photo"] as? PFFile {
imgData.getDataInBackgroundWithBlock({
(imageData: NSData?, error: NSError?) -> Void in
if (error == nil){
let image = UIImage(data: imageData!)
post.image = image
}
})
}
}
}
selectedTableView.reloadData()
我看了回答here但它對我來說沒有意義。