Ios 表视图中空数组的Swift索引0超出边界
我正在尝试使用parse填充tableview,其中有两个标签连接到主电视控制器和PFTableViewCell 当我添加(numberOfSectionsInTableView+numberOfRowsInSection)时,应用程序崩溃 但当我删除它的作品,但它显示什么 这是表格视图单元格Ios 表视图中空数组的Swift索引0超出边界,ios,uitableview,swift,parse-platform,Ios,Uitableview,Swift,Parse Platform,我正在尝试使用parse填充tableview,其中有两个标签连接到主电视控制器和PFTableViewCell 当我添加(numberOfSectionsInTableView+numberOfRowsInSection)时,应用程序崩溃 但当我删除它的作品,但它显示什么 这是表格视图单元格 class courseCell: PFTableViewCell { @IBOutlet var name: UILabel! @IBOutlet var location: U
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
的文档,您似乎不应该覆盖这两个方法
–应根据对象为表中的所有行调用tableView:cellForRowAtIndexPath:object:
。您不应该覆盖numberOfSectionsInTableView
和numberofrowsinssection
,因为解析控制器为您处理所有这些。您正在重写这些方法,并对一个数字进行硬编码,这会导致Parse尝试获取超出边界的行(该行不存在)的对象。看起来您的数据源中实际上没有对象。是的,我第一次这样做时跳过了这两个方法“delete”,但视图控制器不查看任何内容,如果您可以看到Parse对象的两个图像+空表视图不从Parse的数据源“core”获取任何内容有两个标签连接到pftableviewCell明白了问题是你的答案+类应该是大写:)@JamesMoriarty你能发布你修复的屏幕截图吗?我在PFTableView中遇到了这个问题,现在我在PFCollectionViewController中又遇到了这个问题。不记得我是怎么修好的。