0
私のtableViewネットワークからの画像のリストを表示します。次のコントローラに画像データを渡そうとしましたが、失敗しました。 これは私のステップです:スウィフト2テーブルビューネットワークから次のコントローラに画像を渡す
1)空のUIImage変数を宣言する=> 2)url =>からセルのイメージを設定する3)ユーザーがセルを選択したときにイメージを取得する=>次のセルに渡すコントローラ
しかし、あなたがあなたのprepareForSegueでタップセルの参照を取得する必要が
var myImage: UIImage?
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! customCell
if let cellImage = URLArray[indexPath.row]["image"] {
do {
let imgURL: NSURL = NSURL(string: cellImage!)!
let request: NSURLRequest = NSURLRequest(URL: imgURL)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request){
(data, response, error) -> Void in
if (error == nil && data != nil) {
func display_image() {
cell.placeImage.image = UIImage(data: data!)!
}
dispatch_async(dispatch_get_main_queue(), display_image)
} else {
cell.placeImage.image = UIImage(named: "image1")!
}
}
task.resume()
}
}
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let selectedCell = tableView.cellForRowAtIndexPath(indexPath)! as! customCell
self.myImage = selectedCell.placeImage.image
performSegueWithIdentifier("showDetail", sender: self)
}
// prepareForSegue
if segue.identifier == "showDetail" {
let controller = (segue.destinationViewController as! secondViewController)
controller.Image = self.myImage
私は既にセグの識別子を設定しています。そして、それは動作していません...私はこの問題を解決する方法がわかりません。 –
"performSegueWithIdentifier(" showDetail "、sender:self)"を削除しようとすると、ストーリーボードと競合している可能性があります – Ezechiele