0
你好,我開始學習迅速和一個小項目,我使用一個UITableView,但我有一個錯誤,當我嘗試註冊有我的原型細胞筆尖(vwTblCell.xib)UITableView的原型細胞錯誤EXC_i386_INVOP
主題1:EXC_BAD_INSTRUCTION(代碼= EXC_i386_INVOP,子碼=爲0x0)
這是我得到的錯誤:
tableView.registerNib(nib, forCellReuseIdentifier: "Cell")
這是我使用的代碼。
ViewController.swift
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
var nib = UINib(nibName: "vwTblCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "Cell")
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.items.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as TblCell
cell.lblCell.text = self.items[indexPath.row]
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println("Row \(indexPath.row) selected")
}
func tableView(tableView:UITableView!, heightForRowAtIndexPath indexPath:NSIndexPath)->CGFloat
{
return 44
}
}
TblCell.swift
class TblCell: UITableViewCell {
@IBOutlet weak var lblCell: UILabel!
@IBOutlet weak var btnCell: UIButton!
override init(style: UITableViewCellStyle, reuseIdentifier: String!) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
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
}
}
有無添加引用出口你委託了嗎? – casillas
你缺少以下代表 - > class yourClass:UITableViewDelegate,UITableViewDataSource { // ... }' – casillas
我已經有代表,我忘了在問題中添加它們 –