【发布时间】:2015-10-27 15:33:09
【问题描述】:
我遇到问题可能是由于 Swift 的新更新版本。问题是这行代码不断产生一个错误说:
"可选类型'()的值?'没有打开;你是不是要使用“!”还是“?”?
cell?.hypeImageView?.image = UIImage(data: imageData)
这是整个函数:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
var cell:HypeTableViewCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? HypeTableViewCell
if(cell == nil) {
cell = NSBundle.mainBundle().loadNibNamed("HypeTableViewCell", owner: self, options: nil)[0] as? HypeTableViewCell
}
if let pfObject = object {
cell?.hypeNameLabel?.text = pfObject["name"] as? String
var votes:Int? = pfObject["votes"] as? Int
if votes == nil {
votes = 0
}
cell?.hypeVotesLabel?.text = "\(votes!) votes"
let credit:String? = pfObject["cc_by"] as? String //if prob change to var
if credit != nil {
cell?.hypeCreditLabel?.text = "\(credit!) / CC 2.0"
}
cell?.hypeImageView?.image = nil
if var urlString:String? = pfObject["url"] as? String {
var url:NSURL? = NSURL(string: urlString!)
if var url:NSURL? = NSURL(string: urlString!) {
var error:NSError?
var request:NSURLRequest = NSURLRequest(URL: url!, cachePolicy: NSURLRequestCachePolicy.ReturnCacheDataElseLoad, timeoutInterval: 5.0)
NSOperationQueue.mainQueue().cancelAllOperations()
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {
(response:NSURLResponse!, imageData:NSData!, error:NSError!) -> Void in
cell?.hypeImageView?.image = UIImage(data: imageData)
})
}
}
}
return cell
}
我该如何解决这个问题?
【问题讨论】: