我的图像没有显示在我的新 View 中,它在我的控制台中显示了 url,但在模拟器或设备上没有显示。我从 firebase 获取数据并将其发送到名为 User 的类。然后数据显示在我的 tableViewCell 上,我继续到一个新的 ViewController,但是 ImageView 是空白的。
//我的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!
}
}
//我的目的地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!)
}
最佳答案
将此行 destination.imageOneUrl = userList[selectedRow].image!
替换为
destination.imageOne = userList[selectedRow].image!
或
将图像 URL 从 tableViewCell 传递到新 Controller ,然后像在 tableview 委托(delegate)中所做的那样从缓存中加载图像。
关于ios - uitableViewCell 图像到新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43164043/