2016-01-20 127 views
0

我正在尝试使用自定义UITableViewCell
设置: 的Xcode 7.1,迅速,在仿真器运行
步骤:
1.创建新的 “可可触摸类”(CMD + N)与UITableViewCell
2.子类还可以创建XIB文件,创建时swift文件。
3.现在我想向厦门国际银行文件加载到TableViewController
无法加载xib文件

override func viewDidLoad() { 
     super.viewDidLoad() 

    let yourNibName = UINib(nibName: "MyTableViewCell", bundle: nil) 
    tableView.registerNib(yourNibName, forCellReuseIdentifier: "test") // << EXC_BAD_INSTRUCTION 
... 

我得到:Thread 1: EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP, subcode=0x0)

信息:
1.我可以在调试区看到:那个yourNibName有内存地址,但所有其他属性是0x0。因此XIB不能被加载?
2.我可以看到它是检查员中的成员:目标成员
3.它在“构建阶段/复制捆绑软件资源”中
4.我做的产品清理每一件我正在尝试的东西。
但是为什么?

+0

你加你的笔尖到项目的目标是什么? – gasparuff

+0

是的:我可以看到它是“检查员:目标成员”中的成员。 –

+0

您是否将“MyTableViewCell”标识符添加到原型单元格中? – JAL

回答

1

试试这个

你最应该像这样

class myTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 

视图做负载FUNC这样的:

tableView.registerNib(UINib(nibName: "MyTableViewCell", bundle: nil), forCellReuseIdentifier: "test") 
      tableView.delegate = self 
      tableView.dataSource = self 

和本功能是这样的:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

     let cell = tableView.dequeueReusableCellWithIdentifier("test", forIndexPath: indexPath) as! MyTableViewCell 

     tableView.rowHeight = 470 
     tableView.allowsSelection = false 

     return cell 
    } 

如果它不是w ork让我知道..

+0

谢谢,但我得到了同样的错误。 –

+0

in MyTableViewCell.xib您的单元格标识符应该是“test”,以便检查它是否相同,并且您还应该检查“MyTableViewCell”中是否没有拼写错误 –

+0

感谢Ondra,我从代码创建了ViewController并且错过了自我。查看本身: -/ –

0

人们只希望在Xcode中更好的错误消息。这就是说我从代码创建了一个TableViewController,并且缺少视图本身。

self.tableView = UITableView(frame:self.view.frame) 

而且ofcource你不能做是零角度东西,这包括试图tableView.registerNib