我使用parse.com框架与Swift和PFQueryTableViewController时,我设置分页它将无法正常工作。如果数据库的行数少于objectPerPage中设置的数量,那么它工作正常,但如果有更多的行,并且当我运行应用程序时,它会一直显示加载屏幕,并且没有任何内容被下载,当我刷新时刷新它会崩溃 错误PFQueryTableViewController分页不适用于heightForRowAtIndexPath
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]
ImagesTableViewController.swift
import UIKit
import Parse
import ParseUI
import Bolts
class ImagesTableViewController: PFQueryTableViewController {
@IBAction func unwindToSegue (segue : UIStoryboardSegue) {}
// Initialise the PFQueryTable tableview
override init(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// Configure the PFQueryTableView
self.parseClassName = "Image"
self.pullToRefreshEnabled = true
self.paginationEnabled = true
self.objectsPerPage = 5
}
// Define the query that will provide the data for the table view
override func queryForTable() -> PFQuery {
var query = PFQuery(className: "Image")
query.whereKey("deleted", notEqualTo: 1)
query.orderByDescending("createdAt")
return query
}
//override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("ImageCell") as! ImageTVCell!
if cell == nil {
cell = ImageTVCell(style: UITableViewCellStyle.Default, reuseIdentifier: "ImageCell")
}
// Extract values from the PFObject to display in the table cell HEADLINE
if let caption = object?["caption"] as? String {
cell?.headlineLabel?.text = caption
}
// Display image
var initialThumbnail = UIImage(named: "question")
cell.postImageView.image = initialThumbnail
if let thumbnail = object?["image"] as? PFFile {
cell.postImageView.file = thumbnail
cell.postImageView.loadInBackground()
}
return cell
}
// if I remove this code pagination work but the cell height is wrong
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return calculateHeightForRowAtIndexPath(indexPath)
}
func calculateHeightForRowAtIndexPath(indexPath: NSIndexPath) -> CGFloat {
if let ratio = objectAtIndexPath(indexPath)?["aspect"] as? Float {
println("Ratio: \(ratio)")
return tableView.bounds.size.width/CGFloat(ratio)
} else {
return 50.0
}
}
@IBAction func addNewPhotoButton(sender: UIBarButtonItem) {
self.tabBarController?.tabBar.hidden = true
self.performSegueWithIdentifier("showUploadNewImage", sender: self)
}
}
谢谢你的回复,我说是正确的:如果我将用“刷新”功能,我还可以设置手动创建小区'self.paginationEnabled = FALSE' ? 的事情是,当我删除 '覆盖FUNC的tableView(的tableView:UITableView的,heightForRowAtIndexPath indexPath:NSIndexPath) - > CGFloat的{ 回报calculateHeightForRowAtIndexPath(indexPath) }' 的应用程序运行完美,但细胞高度搞砸,最后一个单元格是单元格Load more。我不明白的是,** heightForRowAtIndexPath **正在计算单元格高度,所以为什么它禁用分页... –
你必须插入上面的方法的代码片段之间的其他方法。我将编辑答案来反映这一点。 – Kumuluzz
测试您发布的代码是我做的第一件[屏幕截图](https://www.anony.ws/image/D6cZ),但加载更多数据的最后一个单元未显示... –