[英]How do I pass the data from PFTableViewCell to the next ViewController using prepareForSegue in swift 2.0?
[英]How can I add image to PFTableViewCell Swift 2 Xcode 7
我正在尝试使用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
}
我需要知道错误发生在哪一行。 我的猜测是由于某种原因您试图提取的数据为nil。 要检查是否返回了任何内容,请注释掉代码失败的行,然后执行“ print()”。 如果返回nil,则必须尝试其他操作,因为未下载映像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.