Я пытаюсь имитировать Instagram, используя collectionView
с одной ячейкой, представляющей канал, а другая collectionView
в заголовке родительского элемента collectionView
, но не уверен, что это правильный метод.
любые советы или предложения
Пока что я могу отображать данные, отраженные из моей пользовательской ячейки для родителя collectionview
, но в заголовке, который должен содержать истории collectionvew
, это Пусто
Родитель CollectionVIew
или FeedVC
import UIKit
class FeedVC: UIViewController {
var datta = ["hgfhhgh hfgh","erteeertrt","dfdfdfd","ssss"]
var allImages = [UIImage(named: "pants"), UIImage(named: "shirt"), UIImage(named: "tesla"), UIImage(named: "skull"), UIImage(named: "avatar"), UIImage(named: "heart")]
static var rever = [UIImage(named: "skull"), UIImage(named: "avatar"), UIImage(named: "heart"), UIImage(named: "hart"), UIImage(named: "heart"), UIImage(named: "tesla")]
lazy var navSearchBar = UISearchBar()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// var b = UIBarButtonItem.menuButton(self, action: #selector(test), imageName: "avatar")
// navigationItem.leftBarButtonItem = b
}
@IBOutlet weak var profileNavButtonImage: UINavigationItem!
@IBOutlet weak var searchOutlet: UIBarButtonItem!
@IBAction func SearchButtonPressed(_ sender: UIBarButtonItem) {
let sb = storyboard?.instantiateViewController(withIdentifier: "SearchVCID") as! SearchVC
present(sb, animated: true, completion: nil)
}
@objc func test(){
print("pressed")
}
@IBAction func calendarPopUp(_ sender: UIButton) {
print("uop")
let sb = storyboard?.instantiateViewController(withIdentifier: "CalendarPopUpID") as! CalendarPopUp
present(sb, animated: true, completion: nil)
}
}
extension FeedVC: UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return allImages.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "feedCell", for: indexPath) as! FeedCell
cell.userPost.image = FeedVC.rever[indexPath.row]
cell.profileImageOutlet.image = allImages[indexPath.row]
return cell
}
}
extension FeedVC: UINavigationBarDelegate, UISearchBarDelegate{
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
}
}
Пользовательская ячейка для базовых ячеек в CollectionView
или FeedVC
import UIKit
class FeedCell: UICollectionViewCell {
override func awakeFromNib() {
super.awakeFromNib()
profileImageOutlet.layer.cornerRadius = profileImageOutlet.frame.width / 2
}
//MARK: Profile Image
@IBOutlet weak var profileImageOutlet: UIImageView!
//User Post Button Image
@IBOutlet weak var userPost: UIImageView!
// //Like Button Image
// @IBOutlet weak var likeButtonOutlet: UIImageView!
//
// //Comment Button Image
// @IBOutlet weak var commentButtonOutlet: UIImageView!
var stories = [UIImage(named: "skull"), UIImage(named: "avatar"), UIImage(named: "heart"), UIImage(named: "hart"), UIImage(named: "heart"), UIImage(named: "tesla")]
}
extension CollectionViewCell: UICollectionViewDataSource, UICollectionViewDelegate{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return FeedVC.rever.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "storiesCell", for: indexPath) as! StoriesCell
cell.storiesPic.image = FeedVC.rever[indexPath.row]
return cell
}
}
ячейка истории для Collectionview
в заголовке
import UIKit
class StoriesCell: UICollectionViewCell {
override func awakeFromNib() {
super.awakeFromNib()
storiesPic.layer.cornerRadius = storiesPic.frame.height / 2
}
@IBOutlet weak var storiesPic: UIImageView!
}