无法在捆绑中加载Nib

问题描述 投票:0回答:1

我无法将Nib上传到我的表格视图,这个问题也发生在我正在处理的其他应用程序上,即使我确实有一些NIb的文件正常工作。我甚至重新安装Xcode试图解决问题。我注册我的笔尖如下

let test = "test"

let cellNib = UINib(nibName: test, bundle: nil)
tableView.register(cellNib, forCellReuseIdentifier: test) 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: test, for:indexPath) as! testCell //after this function is called I get a crash 
    return cell
}

这是我从崩溃中得到的消息的一部分,我不知道是否有用。

'NSInternalInconsistencyException',原因:'无法在bundle中加载NIB:'NSBundle(已加载)',名称为'tests''***第一次抛出调用堆栈:(0 CoreFoundation 0x000000010afdab0b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x0000000107b98141 objc_exception_throw + 48 2 CoreFoundation 0x000000010b043625 + [NSException raise:format:] + 197 3 UIKit 0x0000000108b59b24 - [UINib instantiateWithOwner:options:] + 501 4 UIKit 0x00000001088ac567 - [UITableView _dequeueReusableViewOfType:withIdentifier:] + 402 5 UIKit 0x00000001088aca4b - [UITableView dequeueReusableCellWithIdentifier:forIndexPath: ] + 71 6 Chaol 0x000000010759ebe9 _TFC5Chaol23QuestionsViewController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 153

我的.XIB文件出现在复制包资源上。

nib xcode8.2
1个回答
3
投票

也许nib文件未添加到目标中。尝试以下步骤:

  1. 在项目>目标>构建阶段 展开Copy Bundle Resources 单击+按钮并添加所需的NIB文件。 按Shift + Cmd + K清理构建,然后运行。
  2. 在.xib文件中 单击File Inspector 在目标成员资格部分中,选择您正在使用的目标
  3. 另外,仔细检查笔尖名称的拼写。
© www.soinside.com 2019 - 2024. All rights reserved.