Я пытаюсь построить компоновку тегов тегов, и я следил за этой темой;Использование необъявленного типа «tagCell» Ошибка. Создание UICollectionViewCell такого типа xib
http://codentrick.com/create-a-tag-flow-layout-with-uicollectionview/
Затем этот код бросил эту ошибку: Use of undeclared type 'tagCell'
.
var tagCell = collectionView.dequeueReusableCellWithReuseIdentifier("tagCell", forIndexPath: indexPath) as! tagCell
Я создал эти файлы; a xib называется tagCell.xib
, файл под названием tagCell.swift
. И я подключил эти файлы в пользовательском классе xib. Я не знаю, в чем проблема, и я следил за темой без пропусков. Возможно, в Swift произошли некоторые изменения.
Мне нужна помощь. Я искал готовые к использованию библиотеки, написанные с помощью быстрого доступа, но я не нашел. Я должен сам его закодировать.
Есть классы.
//
// tagCell.swift
// matchMyTag
//
// Created by Faruk Turgut on 05/12/15.
//
import UIKit
class tagCell: UICollectionViewCell {
@IBOutlet weak var tagTitle: UILabel!
@IBOutlet weak var plusLabel: UILabel!
override func awakeFromNib() {
self.backgroundColor = UIColor(red: 0.8, green: 0.8, blue: 0.8, alpha: 1)
self.tagTitle.textColor = UIColor(red: 0.1, green: 0.1, blue: 0.1, alpha: 1)
self.plusLabel.textColor = UIColor(red: 0.1, green: 0.1, blue: 0.1, alpha: 1)
self.layer.cornerRadius = 4
}
}
//
// skillsNeedsViewController.swift
// matchMyTag
//
// Created by Faruk Turgut on 05/12/15.
// Copyright © 2015 Faruk Turgut. All rights reserved.
//
import UIKit
class skillsNeedsViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
@IBOutlet weak var collectionView: UICollectionView!
let TAGS = ["Tech", "Design", "Humor", "Travel", "Music", "Writing", "Social Media", "Life", "Education", "Edtech", "Education Reform", "Photography", "Startup", "Poetry", "Women In Tech", "Female Founders", "Business", "Fiction", "Love", "Food", "Sports"]
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
let cellNib = UINib(nibName: "tagCell", bundle: nil)
self.collectionView.registerNib(cellNib, forCellWithReuseIdentifier: "tagCell")
self.collectionView.backgroundColor = UIColor.clearColor()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return TAGS.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var tagCell = collectionView.dequeueReusableCellWithReuseIdentifier("tagCell", forIndexPath: indexPath) as! tagCell
return tagCell
}
}
просто обновленный ответ с более подробной информацией. – adolfosrs