【发布时间】:2016-03-10 13:47:34
【问题描述】:
我正在尝试使用 Parse 和 Swift 2 在 PFTableViewCell 中显示一些文本和图像。我能够完全显示单元格内的文本,但是当我添加图像代码以显示和运行应用程序时,它给出了我出现以下错误:“致命错误:在展开可选值时意外发现 nil” 这是我正在使用的代码:
var textArray = [String]()
var imageArray = [UIImage]()
@IBOutlet weak var tableView2: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let shopList = PFQuery(className:"Shops")
let runkey = shopList.orderByAscending("shopName")
runkey.findObjectsInBackgroundWithBlock {(objects: [PFObject]?, error: NSError?) -> Void in
if error == nil {
if let objects = objects as [PFObject]! {
for object in objects {
let loadTxt = object.objectForKey("shopName") as! String
let loadImg = object.objectForKey("shopImages") as! UIImage
self.imageArray.append(loadImg)
self.textArray.append(loadTxt)
print(self.textArray)
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TableViewCell
cell.labelShopName?.text = textArray[indexPath.row]
cell.shopImages?.image = imageArray[indexPath.row]
return cell
}
【问题讨论】:
标签: ios swift uitableview parse-platform tableview