0
我想在PFTableViewCell中使用Parse和Swift 2顯示一些文本和圖像。我能夠完全顯示單元格內的文本,但是當我添加代碼圖像顯示和運行應用程序,它給了我下面的錯誤:「致命錯誤:意外發現零而展開的可選值」 這裏是我使用的代碼:我如何添加圖像到PFTableViewCell Swift 2 Xcode 7
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
}