【发布时间】:2015-06-23 15:44:41
【问题描述】:
我对@987654322@ 还很陌生,我一直在尝试从存储在Parse.com 中的数组中提取单个项目
打印数组本身时,我得到所有用户,但是,当尝试获取数组的第一个索引时,我得到以下错误
“致命错误:无法索引空缓冲区”
这是我目前正在使用的代码 -
import UIKit
import Parse
class feedTableViewController: UITableViewController {
var titles = [String]()
var usernames = [String]()
var images = [UIImage]()
var imageFiles = [PFFile]()
override func viewDidLoad() {
super.viewDidLoad()
//....
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var myCell:cell = self.tableView.dequeueReusableCellWithIdentifier("myCell") as cell
//Error occurs here - does not work due to empty buffer
myCell.title.text = titles[indexPath.row]
myCell.username.text = usernames[indexPath.row]
//If the previous two lines are commented out, I can print out both the arrays
println(titles)
println(usernames)
return myCell
}
}
谢谢!
【问题讨论】:
-
请将您的代码缩减为a Minimal, Complete, and Verifiable example。还请指定您引用的错误发生在哪一行。
-
@AaronBrager 我已经减少了代码并缩小到 xCode 上显示错误的位置。虽然我会认为删除的代码可能有助于其他人更好地理解代码?谢谢
-
println(titles[indexPath.row])打印出您期望的内容吗?titles可能是空的,或者可能比您在numberOfRowsInSection中返回的元素少 -
@AaronBrager 不,它没有。打印出来时它给了我同样的错误。然而,我现在想哭。 numberOfRowsInSection 是罪魁祸首。它不是调用数组的项目数,而是一个集合数。谢谢亚伦。非常感激。你不知道我花了多长时间试图解决这个问题.....
标签: ios swift parse-platform xcode-6.2