Wednesday, September 28, 2022
HomeiOS Developmentios - Swift cells are created however do not present up in...

ios – Swift cells are created however do not present up in UICollectionView swift 5


I am creating a group view with customized assortment view cell. So, I’ve created the gathering view in my storyboard view controller. The issue is that my cells are created in cellForItemAt however they don’t seem to be proven in any respect, I’ve additionally tried utilizing default cells, however they don’t seem to be proven both, and naturally, I’ve tried all of the options I discovered. Thanks for serving to upfront!

view controller class associated elements

   override func viewDidLoad() {
        tremendous.viewDidLoad()
        
        collectionView.delegate = self
        collectionView.dataSource = self
        
        title = set?.identify
        
        
        
        collectionView!.register(WordCollectionViewCell.self, forCellWithReuseIdentifier: Identifies.WordCollectionViewCellIdentifier)
        
        
        let buttonItem  = UIBarButtonItem(barButtonSystemItem: .add, goal: self, motion: #selector(addButtonPressed))
        
        
        navigationItem.rightBarButtonItem = buttonItem
        updateTranslations()
    }

cover: false console: true babel: false –>

extension SingleSetViewController : UICollectionViewDelegate, UICollectionViewDataSource  {
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection part: Int) -> Int {
        print(translations.rely)
        return translations.rely
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Identifies.WordCollectionViewCellIdentifier, for: indexPath) as! WordCollectionViewCell
        
    
        cell.translation = translations[indexPath.row]
    
        return cell
    }
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1 
    }
}

assortment view cell class

class WordCollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var wordLabel: UILabel!
    
    personal var showsWord = true
    
    
    personal var _translation : Translation?
    var translation : Translation  {
        set {
            _translation = newValue
        }
        get {
            return _translation ?? Translation(phrase: "", translation: "")
        }
    }
    override func awakeFromNib() {
        tremendous.awakeFromNib()
        
        let gestureRecognizer = UITapGestureRecognizer(goal: self , motion: #selector(flip))
        gestureRecognizer.numberOfTapsRequired = 1
        self.addGestureRecognizer(gestureRecognizer)
        
        wordLabel.textual content = _translation?.phrase
    }
    
    @objc personal func flip(_ sender: UIGestureRecognizer){
        let choices : UIView.AnimationOptions = [.transitionFlipFromRight]
        UIView.transition(with: self, length: 0.5, choices: choices){
            if let translation = self._translation {
                    self.wordLabel.textual content = self.showsWord ? translation.translation : translation.phrase
                    self.showsWord = !self.showsWord
            }
        }
    }
    
    static func nib() -> UINib {
        return UINib(nibName: NibNames.WordCollectionViewCellNibName, bundle: nil)
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments