gpt4 book ai didi

ios - Swift 4 - 从 UICollectionView 单元格推送 ViewController

转载 作者:行者123 更新时间:2023-11-28 10:06:07 25 4
gpt4 key购买 nike

我被困在我的项目中,需要一些帮助。我想从 UICollectionViewCell including 我的 UINavigationBar 推送/呈现 UICollectionViewController。我了解到您实际上不能从 Cell 中呈现 ViewController?在这种情况下我该怎么办?我的问题是我的 NavigationBar 不会出现。

这是我的手机:

import UIKit
import Firebase

class UserProfileHeader: UICollectionViewCell, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

lazy var followersLabelButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("followers", for: .normal)
button.setTitleColor(UIColor.lightGray, for: .normal)
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)
button.addTarget(self, action: #selector(followers), for: .touchUpInside)
return button
}()

@objc fileprivate func followers() {

let newController = NewController(collectionViewLayout: UICollectionViewFlowLayout())

self.window?.rootViewController?.present(newController, animated: true, completion: nil)


}

}

和 CollectionViewController:

import UIKit
import MapKit
import Firebase

class UserProfileController: UICollectionViewController, UICollectionViewDelegateFlowLayout, UIGestureRecognizerDelegate {

var userId: String?

override func viewDidLoad() {
super.viewDidLoad()

collectionView?.backgroundColor = UIColor.white


collectionView?.register(UserProfileHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "headerId")

}


override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "headerId", for: indexPath) as! UserProfileHeader

header.user = self.user

return header
}


func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {


return CGSize(width: view.frame.width, height: 200)


}


}

最佳答案

1- 细胞内部

weak var delegate:UserProfileController?

2- 内部 cellForItemAt

cell.delegate = self

3- 在单元格内使用它

delegate?.present(newController, animated: true, completion: nil)

顺便说一句,我想你的意思是

delegate?.navigationController?.pushViewController(newController, animated: true)  

关于ios - Swift 4 - 从 UICollectionView 单元格推送 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53433399/

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