Ios 情节提要UITableViewCell无法加载名为的捆绑包中的nib。。。以编程方式加载时
我有一个带有Ios 情节提要UITableViewCell无法加载名为的捆绑包中的nib。。。以编程方式加载时,ios,swift,uitableview,storyboard,nib,Ios,Swift,Uitableview,Storyboard,Nib,我有一个带有UITableView的Viewcontroller场景(故事板),在一个名为Foo的UITableViewCell内Foo从故事板加载时可以正常加载,但我需要以编程方式从另一个UITableView加载它 我正在这样注册单元格(起初我尝试不使用UINib,但是IBOutlets是nil): 然后像这样加载它: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITab
UITableView
的Viewcontroller场景(故事板),在一个名为Foo的UITableViewCell
内Foo从故事板加载时可以正常加载,但我需要以编程方式从另一个UITableView
加载它
我正在这样注册单元格(起初我尝试不使用UINib
,但是IBOutlets
是nil
):
然后像这样加载它:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "bar", for: indexPath) as! Foo
return cell
}
这不起作用并返回错误:
由于未捕获异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法在名为“Foo”的捆绑包:“NSBundle(loaded)”中加载NIB”
我确定的事情:
- 属性检查器中的Foo
标识符为FooUITableViewCell
- 具有正确的目标成员资格
UItableView单元格
移动到UItableView
之外,是否可以执行此操作?如果要重用表视图单元格,则应将其移动到单独的nib文件中。之后,您可以将该单元格注册到所需的任何表视图中。如果将单元格保留在序列图像板文件中视图控制器的表视图中,则无法重用它。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "bar", for: indexPath) as! Foo
return cell
}