gpt4 book ai didi

swift 3 : Pass in the indexPath into another Class

转载 作者:行者123 更新时间:2023-11-30 12:38:16 24 4
gpt4 key购买 nike

我有一个返回帖子数组的collectionView,[Post]。在 collectionViews 单元类(实际的帖子)内部,我有一个名为 profileSegueContainer 的 View 。 isUserInteractionEnabled 当然设置为 true,并且我有一个 UITapGestureRecognizer,它在点击此 View 时运行一个函数。这个函数只是呈现另一个ViewController。我希望当我点击 profileSegueContainer 时能够将 post.uid 传递到此 ViewController 中。我该如何实现这一目标?谢谢。相关代码如下。任何建议将不胜感激...

class Post: NSObject {

var author: String?
var avatar_image_url: String?
var likes: Int?
var postImageUrl: String?
var uid: String?
var post_id: String?
var hashtags: [String]?
}

class PostCell: BaseCell {

var homeController: HomeController?

lazy var profileSegueContainer: UIView = {
let view = UIView()
view.isUserInteractionEnabled = true
return view
}()

override func setupViews() {
super.setupViews()

let tap = UITapGestureRecognizer(target: self, action: #selector(handleProfileSegue))
profileSegueContainer.addGestureRecognizer(tap)

topBar.addSubview(profileSegueContainer)
}

func handleProfileSegue() {
let userProfileController = UserProfileController()
let navigationUserProfileController = UINavigationController(rootViewController: userProfileController)
homeController?.present(navigationUserProfileController, animated: true, completion: nil)
}
}

最佳答案

希望我正确理解您的问题。您想将值传递到新的 UserProfileController 对象中吗?

向您的 UserProfileController 添加属性

class UserProfileController : UIViewController {
public var postId : Int!
// more stuff ....
}

然后,您只需在创建对象后访问该属性即可:

func handleProfileSegue(sender: UITapGestureRecognizer) {
let userProfileController = UserProfileController()
userProfileController.postId = 2345
// more stuff...
}

请告诉我这是否是您所需要的。如果没有,我们将更新我们的帖子。

关于 swift 3 : Pass in the indexPath into another Class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42596646/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com