我有一个collectionView,它返回一个帖子数组,[Post]
。在collectionViews单元类(实际的帖子)里面,我有一个叫profileSegueContainer
的视图。 isUserInteractionEnabled当然设置为true,并且我有一个UITapGestureRecognizer
,它在点击此视图时运行一个函数。这个函数只提供了另一个ViewController。当我点击profileSegueContainer
时,我希望能够将post.uid
传入此ViewController。我如何实现这一目标?谢谢。相关代码如下。任何意见将不胜感激...Swift 3:将indexPath传入另一个类
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)
}
}
可以achive使用自定义点击类,试试这个代码 进口的UIKit 类customTap:UITapGestureRecognizer {VAR objPost:帖子! =零 } // 使用像: 让自来水= customTap(目标:自我,动作:#selector(handleProfileSegue :)) tap.objPost = yourPostDataobject profileSegueContainer.addGestureRecognizer(TAP) –
@Jay Mahta感谢的人。意义重大。你能举个例子吗? – Jimmy
我已更新我的评论。看看它一次。 –