从UITableView推送数据以编程方式查看控制器

问题描述 投票:1回答:1

我正在尝试将数据从tableView推送到View控制器。我可以成功传输一些数据,但是仍然缺少一些关键点。我将尽我所能来说明我的问题。在我的notificationTableView中,我存储了诸如userName,userImage,jobName和jobImage之类的数据。我可以成功地将用户的图像和名称推入,但是jobName和JobImage无法转移,如下图所示。

firstImage

在此图像中,我们可以看到具有userName,userImage,jobName和jobImage的tableView部分。

second image

在第二个图像中,我们可以看到usersName和Image被成功推送。但是,不传输jobImage和名称。

我用来传递信息的代码是

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    let notification = notifications[indexPath.row]
    if notification.notificationType != .swipe {

        let acceptWorker = jobProgressViewController()
        acceptWorker.workerUser = myUser
        acceptWorker.workerUser = notification.user
        jobProgressView?.myParentViewController = self
        let navController = UINavigationController(rootViewController: acceptWorker)
                  present(navController, animated: true, completion: nil)

    } else {
   print("something else should go here")
}

和下面用于检索信息的代码。这是我的jobProgressViewController

     var notification: userNotifications?
     var workerUser: User? {

didSet {
    let name = workerUser?.name
    workerNameLabel.text = name


    guard let profileImage = workerUser?.profileImageUrl else { return }
    workerImageView.loadImageUsingCacheWithUrlString(profileImage)

    if let post = notification?.poster {
        jobImageView.loadImageUsingCacheWithUrlString(post.imageUrl1!)
        jobLabel.text = post.category
        addressLabel.text = post.category
                      }

}
}

   fileprivate func setupView(){
    let postUser = workerUser.self
    let uid = Auth.auth().currentUser?.uid
    let userName = postUser?.name
    let posterId = postUser?.uid
    let post = notification?.poster

    guard let userImage = workerUser?.profileImageUrl else { return }
    Database.database().reference().child("users").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in
        guard let dictionary = snapshot.value as? [String : Any] else { return }
        let user = User(dictionary: dictionary as [String : AnyObject])

        let currentUser = MyUser(dictionary: dictionary as [String : AnyObject])
        self.posterImageView.image = #imageLiteral(resourceName: "user")
        self.posterImageView.loadImageUsingCacheWithUrlString(userImage)

        self.userNameLabel.text = userName
        self.userNameLabel.font = UIFont.systemFont(ofSize: 30)
        self.userNameLabel.textColor = UIColor.black

        self.workerImageView.image = #imageLiteral(resourceName: "user")
        self.workerImageView.loadImageUsingCacheWithUrlString(currentUser.profileImageUrl!)

        self.workerNameLabel.text = currentUser.name
        self.workerNameLabel.font = UIFont.systemFont(ofSize: 30)
        self.workerNameLabel.textColor = UIColor.black


        self.addressLabel.text = postUser?.address
        self.addressLabel.font = UIFont.systemFont(ofSize: 30)
        self.addressLabel.textColor = UIColor.black

        self.jobLabel.text = post?.category
        self.jobLabel.font = UIFont.systemFont(ofSize: 30)
        self.jobLabel.textColor = UIColor.black



    }, withCancel: { (err) in
        print("attempting to load information")

    })
     print("this is your uid \(posterId!)")
}

以下是我填充notificationCell的方式,该方法在tableView中显示用户信息

    var jobProgressView: jobProgressViewController? = nil

 var delegate: NotificationCellDelegate?

var notification: userNotifications? {
    didSet {


       guard let user = notification?.user else { return }
       guard let profileImageUrl = user.profileImageUrl else { return }


        profileImageView.loadImageUsingCacheWithUrlString(profileImageUrl)
        configureNotificationLabel()
        configureNotificationType()

        if let post = notification?.poster {
            postImageView.loadImageUsingCacheWithUrlString(post.imageUrl1!)
        }
    }
}

    func configureNotificationLabel() {
    guard let notification = self.notification else { return }
    guard let user = notification.user else { return }
    guard let poster = notification.poster else { return }
    guard let username = user.name else { return }
    guard let notificationDate =  configureNotificationTimeStamp() else { return }
    guard let jobName = poster.category else { return }

    let notificationMessage = notification.notificationType.description

    let attributedText = NSMutableAttributedString(string: username, attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 14)])

    attributedText.append(NSAttributedString(string: notificationMessage , attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14), NSAttributedString.Key.foregroundColor: UIColor.black]))

    attributedText.append(NSAttributedString(string: jobName, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14), NSAttributedString.Key.foregroundColor: UIColor.black]))

    attributedText.append(NSAttributedString(string: " \(notificationDate).", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14), NSAttributedString.Key.foregroundColor: UIColor.gray]))
        notificationLabel.attributedText = attributedText
}

[如果有任何可能我遗漏的信息无法帮助您获得答案,请告诉我。谢谢,麻烦您了。

ios xcode uitableview push pushviewcontroller
1个回答
1
投票

作为讨论,您忘记了jobProgressViewController的设置通知>

在func didSelectRowAt indexPath中添加以下代码:

acceptWorker.notification = notification
© www.soinside.com 2019 - 2024. All rights reserved.