SDWebImageを使用してTableViewに読み込んだイメージを、フルスクリーンで表示できるビュー(DetailView)にプッシュする方法を見つけようとしています。SDWebImageイメージを詳細ビューにプッシュする方法
私は、テーブルビュー上に正しく表示されているURLから読み込まれた画像を持っています。しかし、私が1つをタップすると、そこにUIImageがあるときに空白の別のビュー(DetailView)が表示されます。何らかの理由で、画像がロードされていません。
ありがとうございます!ここで
は、テーブルビューのコードである:ここで
import UIKit
class TableViewController: UITableViewController {
var imageURLs = [String]()
override func viewDidLoad() {
super.viewDidLoad()
imageURLs = ["https://i.imgur.com/lssFB4s.jpg","https://i.imgur.com/bSfVe7l.jpg","https://i.imgur.com/vRhhNFj.jpg"]
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "DetailView") {
let VC = segue.destinationViewController as! DetailViewController
if let indexpath = self.tableView.indexPathForSelectedRow {
let Imageview = imageURLs[indexpath.row] as String
VC.SentData1 = Imageview
}
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
let cell2: TableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! TableViewCell
let imagename = UIImage(named: imageURLs[indexPath.row])
cell2.cellImage.image = imagename
let imageView = cell?.viewWithTag(1) as! UIImageView
imageView.sd_setImage(with: URL(string: imageURLs[indexPath.row]))
return cell!
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return imageURLs.count
}
はDetailViewコードです:
import UIKit
class DetailViewController: UIViewController {
@IBOutlet weak var Detailimageview: UIImageView!
var SentData1:String!
override func viewDidLoad() {
super.viewDidLoad()
Detailimageview.image = UIImage(named: SentData1)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
おかげのような何かをすることによってそれをあなたがあなたのテーブルビューのセルにそれをやっているのと同じ方法をロードする必要があります。私は言うエラーを取得しています:タイプの値 'UIImage?'何のメンバーがありません「sd_setImage」 明確にするためには、私はそれを上に貼り付けています:Detailimageview.image = UIImage(命名:SentData1)は は、このエラーがSDWebImageがDetailViewController上に「ロードされ」ていないということですか? ありがとう! – Miles
申し訳ありませんが、それはタイプミスでした。固定 – Paulw11
それは素晴らしい動作します!本当にありがとう、ありがとう! – Miles