[英]tableViewCell image to new view
My image is not showing in my new view, it shows the url in my console but not on the simulator or device. 我的图像没有显示在我的新视图中,它在我的控制台中显示了网址,但在模拟器或设备上没有显示。 I am getting the data from firebase and sending it to a class named User.
我从firebase获取数据并将其发送到名为User的类。 The data then shows on my tableViewCell and I segue to a new ViewController, however the image view is blank.
然后数据会显示在我的tableViewCell上,然后我会转到一个新的ViewController,但是图像视图是空白的。
//my code for tableViewController //我的tableViewController代码
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "prefCell", for: indexPath) as! SFPTableViewCell
let user = userList[indexPath.row]
cell.name.text = userList[indexPath.row].name
cell.location.text = userList[indexPath.row].location
cell.bio.text = userList[indexPath.row].bio
if let imageURL = user.image {
cell.imageOne.loadImageUsingCacheWithUrlString(urlString: imageURL)
}
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? SFProfileViewController{
let cell = sender as! UITableViewCell
let selectedRow = tableView.indexPath(for: cell)!.row
destination.nameProfile = userList[selectedRow].name!
destination.locationProfile = userList[selectedRow].location!
destination.imageOneUrl = userList[selectedRow].image!
}
}
//my destination ViewController //我的目的地ViewController
class SFProfileViewController: UIViewController, UITableViewDelegate {
@IBOutlet weak var nameLabelTwo: UILabel!
var user: User?
var userList = [User]()
@IBOutlet weak var imageOne: UIImageView!
var imageURL: String?
var imageOneUrl: String!
var nameProfile : String!
var locationProfile: String!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var locationLabel: UILabel!
override func viewWillAppear(_ animated: Bool) {
print(locationProfile)
print(nameProfile)
print(imageOneUrl)
imageOne.image = UIImage(named: imageOneUrl)
nameLabelTwo.text = String(describing: nameProfile!)
nameLabel.text = String(describing: nameProfile!)
locationLabel.text = String(describing: locationProfile!)
}
Replace this line destination.imageOneUrl = userList[selectedRow].image!
替换此行
destination.imageOneUrl = userList[selectedRow].image!
with 同
destination.imageOne = userList[selectedRow].image!
OR 要么
Pass the image URL from tableViewCell to new Controller and then load the image from cache as you are doing in tableview delegate. 将图像URL从tableViewCell传递给新的Controller,然后像在tableview委托中那样从缓存加载图像。
Change below line and pass imageOne Url instead of image 更改下面的行并传递imageOne Url而不是图像
imageOne.image = UIImage(named: imageOneUrl)
To 至
imageOne.loadImageUsingCacheWithUrlString(urlString: imageURL)
As imageoneurl is url not image name 由于imageoneurl是url而不是图像名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.