我有一個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
我已更新我的評論。看看它一次。 –