2015-04-06 85 views
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 
    } 

} 

Image1 Image2

+0

有无添加引用出口你委托了吗? – casillas

+0

你缺少以下代表 - > class yourClass:UITableViewDelegate,UITableViewDataSource { // ... }' – casillas

+0

我已经有代表,我忘了在问题中添加它们 –

回答

0

修正:好像我忘了在故事板