当前正在使用Xcode版本6.0.1并尝试创建自己的自定义tableViewCell。 我已经设置了XIB文件出现像这样使用故事板在swift中创建自定义TableViewCell
代码RecipeTableViewCell类
import UIKit
类RecipesTableViewCell:{UITableViewCell的
@IBOutlet weak var recipeImage: UIImageView!
@IBOutlet weak var nameLabel:UILabel!
@IBOutlet weak var prepTimeLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
在我tableViewController类我的代码看起来像这个控制单元格的主要方法。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell:RecipesTableViewCell? = tableView.dequeueReusableCellWithIdentifier("cell2") as? RecipesTableViewCell
if cell == nil{
//var nib:NSArray = NSBundle.mainBundle().loadNibNamed("RecipesTableViewCell", owner: self, options: nil)
var tempController:UIViewController = UIViewController(nibName: "RecipesTableViewCell", bundle: nil)
cell = tempController.view as? RecipesTableViewCell
println(cell)
}
cell?.prepTimeLabel.text = "5 mins"
cell?.nameLabel.text = "HellO"
return cell!
}
任何时候,我运行它给我的应用程序
致命错误:意外发现零而展开的可选值 (LLDB)
如果在调用崩溃'dequeueReusableCellWithIdentifier'它可能是你没有正确设置你的小区标识。由于检查员在屏幕上不可见,我不能说是否是这种情况。同时检查您是否已将所有插座连接到正确的目标。尽管他们应该有点点滴滴,但你可能已经将两个网点连接到同一个目标。 – 2014-10-19 11:18:19