大家好我在Makeschool的makestagram项目中快速练习, 我想让最新的帖子显示在表格视图的顶部 让用户可以先看到最新的帖子!
任何人都可以帮忙吗? 这是我的代码
override func viewDidLoad() {
super.viewDidLoad()
timelineComponent = TimelineComponent(target: self)
self.tabBarController?.delegate = self
}
func takePhoto(){
// instantiate photo taking class, provide callback for when photo is selected
photoTakingHelper = PhotoTakingHelper(viewController: self.tabBarController!,callback:{ (image: UIImage?)in
let post = Post()
post.image.value = image!
post.uploadPost()
}
)
}
override func viewDidAppear(animated: Bool) {
timelineComponent.loadInitialIfRequired()
}
func loadInRange(range: Range<Int>, completionBlock: ([Post]?) -> Void) {
ParseHelper.timelineRequestForCurrentUser(range) {
(result: [PFObject]?, error: NSError?) -> Void in
if let error = error {
ErrorHandling.defaultErrorHandler(error)
}
let posts = result as? [Post] ?? []
completionBlock(posts)
}
}
}
extension TimelineViewController: UITableViewDataSource {
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return self.timelineComponent.content.count
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("PostCell")as! PostTableViewCell
let post = timelineComponent.content[indexPath.section]
post.downloadImage()
post.fetchLikes()
cell.post = post
return cell
}
}
extension TimelineViewController: UITableViewDelegate{
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
timelineComponent.targetWillDisplayEntry(indexPath.section)
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerCell = tableView.dequeueReusableCellWithIdentifier("PostHeader")as! PostSectionHeaderView
let post = self.timelineComponent.content[section]
headerCell.post = post
return headerCell
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 40
}
}
答案 0 :(得分:0)
我终于搞清楚了!
parse的PFquery得到了更新方法
我将createdAt更改为updatedAt。
现在它完美无缺!