2016-10-05 2 views
0

SDWebImage를 통해 TableView에로드 된 이미지를 전체 화면으로 볼 수있는 뷰 (DetailView)로 푸시하는 방법을 찾으려고합니다.SDWebImage 이미지를 자세히보기로 푸는 방법

테이블 뷰에 표시되는 URL에서 이미지를 올바르게로드했습니다. 하지만 하나를 탭하면 다른 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. 
} 
*/ 

답변

1

당신은 UIImage(named:)를 사용하는 목적지 VC에서

는 여기에있는 TableView 코드입니다. 그러면 네트워크가 아닌 번들에서 이미지가로드됩니다. 당신은로드 할 때 속성과 변수는 규칙

+0

감사합니다 뭔가를 수행하여있는 tableview 세포에 당신이 그 일을하는 것과 같은 방법으로로드해야합니다. 다음과 같은 오류가 나타납니다 : 'UIImage'유형의 값? 어떤 회원이 없습니다 'sd_setImage' 명확하게하기 위해, 내가 그것을 넘어서 붙여 오전 : Detailimageview.image =있는 UIImage (이름 : SentData1이) 이 오류가 SDWebImage가 DetailViewController에 "로드"되지 않았습니다 의미 하는가? 감사합니다. – Miles

+0

죄송합니다. 오타였습니다. 고정 – Paulw11

+0

그것은 잘 작동합니다! 고마워요, 고마워요! – Miles

0

에 의해 소문자로 시작해야

Detailimageview.sd_setImage(with: URL(string:self.SentData1)) 

참고 : (또는 캐시를 통해 이미 인출 된 경우) 네트워크에서를 가져 sd_setImage를 사용한다 상세 뷰에서로드하려는 이미지의 웹 URL을 전달하지만 UIImage(named: SentData1)으로 번들에서로드하려고합니다.

대신 그냥 응답 Detailimageview.sd_setImage(with: URL(string: SentData1))

+0

답변 해 주셔서 감사합니다. 다음과 같은 오류가 나타납니다 : 'UIImage'유형의 값? SDWebImage가 DetailViewController에로드되지 않았다는 의미입니까? 예를 들어, 'sd_setImage' 고맙습니다! – Miles

+0

내가 준 코드로 어떻게 오류가 발생하는지 알지 못합니다. 다른 일을하지 않았습니까? – Dima

+0

Paulw11이 약간 다른 코드 줄을 사용하여 아래에 답변했습니다. Detailimageview.sd_setImage (with : URL (string : self.SentData1))이 코드는 작동하는 것 같습니다. 도움에 감사드립니다! – Miles