使用未声明的类型 "tagCell" 错误。创建那种 xib 的 UICollectionViewCell
Use of undeclared type "tagCell" Error. Creating UICollectionViewCell that kind of 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
我创建了这些文件;一个名为 tagCell.xib
的 xib,一个名为 tagCell.swift
的文件。并且我在xib的自定义class下连接了这些文件。我不知道是什么问题,我没有遗漏地跟随主题。也许在 swift 2 中有一些变化。
我需要帮助。我寻找准备使用通过 swift 编写的库,但我没有找到。我现在必须自己编写代码。
有 class 个。
//
// 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
}
}
您需要在您的手机上设置重用标识符。
只需打开您的情节提要,select 集合视图中的单元格并将其设置如下:
更新:
此外,您必须始终使用 CamelCase 命名您的 classes。 因此更改 class 名称、.swift 文件名以及任何您想调用 class 的地方,将其命名为 TagCell。虚线现在应如下所示:
var tagCell = collectionView.dequeueReusableCellWithReuseIdentifier("tagCell", forIndexPath: indexPath) as! TagCell
对我来说,它在退出 Xcode 和 运行 后工作正常
我正在尝试构建标签流布局并且我正在关注这个主题;
http://codentrick.com/create-a-tag-flow-layout-with-uicollectionview/
然后这段代码抛出了这个错误:Use of undeclared type 'tagCell'
.
var tagCell = collectionView.dequeueReusableCellWithReuseIdentifier("tagCell", forIndexPath: indexPath) as! tagCell
我创建了这些文件;一个名为 tagCell.xib
的 xib,一个名为 tagCell.swift
的文件。并且我在xib的自定义class下连接了这些文件。我不知道是什么问题,我没有遗漏地跟随主题。也许在 swift 2 中有一些变化。
我需要帮助。我寻找准备使用通过 swift 编写的库,但我没有找到。我现在必须自己编写代码。
有 class 个。
//
// 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
}
}
您需要在您的手机上设置重用标识符。
只需打开您的情节提要,select 集合视图中的单元格并将其设置如下:
更新:
此外,您必须始终使用 CamelCase 命名您的 classes。 因此更改 class 名称、.swift 文件名以及任何您想调用 class 的地方,将其命名为 TagCell。虚线现在应如下所示:
var tagCell = collectionView.dequeueReusableCellWithReuseIdentifier("tagCell", forIndexPath: indexPath) as! TagCell
对我来说,它在退出 Xcode 和 运行 后工作正常