ios - uitableViewCell 图像到新 View

标签 ios swift uitableview uiimage

我的图像没有显示在我的新 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/

相关文章:

ios - 提交 App UIApplicationExitsOnSuspend 时出现错误 ITMS-90040

ios - 如何计算弯曲的 SKSpriteNode 的 "center"点?

ios - Swift - 文本字段键盘返回键不起作用?

Iphone:UITableView 如何检测该行被选中

ios - swift 中的ConfigureAwait 方法的模拟

ios - 在 UIManagedDocument 中禁用自动保存

ios - UITableViewCell swift 3 之间的间距

ios - 如何使 UITableViewCell 调整高度以适应其内容?

ios - iOS 应用程序上的 Swift 按钮错误,但在 playground 中没有

xcode - 为什么 SKNode 在 SpriteKit 游戏中对触摸没有反应?