Swift索引0超出了在tableview中为空数组的界限

我试图填充tableview与parsing与2个标签连接到与PFTableViewCell的主要电视控制器

当我添加(numberOfSectionsInTableView + numberOfRowsInSection)应用程序崩溃

但是当我删除它的作品,但它什么都没有显示。

在这里输入图像说明在这里输入图像说明

这个表格视图单元格

class courseCell: PFTableViewCell { @IBOutlet var name: UILabel! @IBOutlet var location: UILabel! } 

这个表视图控制器

 class courseTVC: PFQueryTableViewController { override init!(style: UITableViewStyle, className: String!) { super.init(style: style, className: className) } required init(coder aDecoder:NSCoder) { super.init(coder:aDecoder) self.parseClassName = "courses" self.textKey = "Location" self.pullToRefreshEnabled = true self.paginationEnabled = false } override func queryForTable() -> PFQuery! { var query = PFQuery(className: "courses") query.orderByDescending("Location") return query } override func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 4 } override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell { var cell = tableView.dequeueReusableCellWithIdentifier("cell" , forIndexPath : indexPath) as? courseCell if cell == nil { cell = courseCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell") } cell!.name.text = object["Price"] as! String! cell!.location.text = object["Location"] as! String! return cell! } 

调试消息

我不知道如何解决这个问题

看看PFQueryTableViewController的文档, https: PFQueryTableViewController它看起来像你不应该重写这两个方法。

– tableView:cellForRowAtIndexPath:object:应根据您的objects已经为您的表中的所有行调用。 你不应该重写numberOfSectionsInTableViewnumberOfRowsInSection因为parsing控制器为你处理所有这些。 您正在重写这些方法并对一个数字进行硬编码,这会导致Parse尝试对超出边界(不存在)的行进行提取和对象操作。 看起来你的数据源中实际上没有对象。