2

When I deleted xib files for my view controllers, I got this error: "Could not load NIB in bundle...with name 'LibraryViewController'". I referenced this question.

Things I have already done:

  • Deleted app from simulator
  • Deleted derived data
  • Cleaned build folder
  • Restarted my computer
  • Attempted to clean the contents of /var/folders. However, I could not delete the folders 8k, gf, and zz inside /var/folders because they are required by Mac OS.

Is there any way I can delete my unused xib files without crashing my app?

Update:

 override func viewDidLoad() {
      libraryTable.register(UINib(nibName: "categoriesTableViewCell", bundle: nil), forCellReuseIdentifier: "categoriesTableViewCell")
 }

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if indexPath.section == 0  {
        let cell = tableView.dequeueReusableCell(withIdentifier: "categoriesTableViewCell", for: indexPath) as! categoriesTableViewCell
        return cell
    } else {
        let cell = songTableViewCell()
        return cell
    }
}
Alex
  • 2,369
  • 3
  • 13
  • 23
  • Do you manually load your view controllers from a .xib or a storyboard, or is everything done using IB? Is it possible your error is due to code that you still have which tries to load the .xib that is no longer there? If so, you could create a new .xib, or create a view controller in code if you still need the functionality. – Mozahler Jul 03 '17 at 03:28
  • When I first created the view controllers, I checked "Also create a XIB file". I did not put anything on the view controller xib file and I did not register the xib file in my code, so the view controllers should be loading by code only. However, the compiler still compiles those view controller XIB files – Alex Jul 03 '17 at 18:41
  • @Mozahler do you know if there's a solution to my problem? – Alex Jul 05 '17 at 15:09
  • I thought I did, but your last note confused me. If you deleted the files, how can the compiler compile them? If the .xib files are truly deleted, those files aren't causing your error. Your error is due to code that you still have which tries to load the .xib that is no longer there. Can you show your code where you register your cell that you dequeue? also the line in cellForRowAt where you dequeue a cell. That should tell us what we need to know. The other possibility is you have a reference to the cell in IB that needs to be updated. – Mozahler Jul 05 '17 at 15:20
  • @Mozahler okay I updated my answer. Also, I'm trying to delete "LibraryViewController.xib" that's associated with my library view controller. The view controller xib is completely independent of the table view cell xib, "categoriesTableViewCell.xib", so I'm not sure why the requested code is needed – Alex Jul 07 '17 at 01:50
  • Is categoriesTableviewCell the xib you deleted? If yes, just register a cell as a uitableviewcell and you're good to go. – Mozahler Jul 07 '17 at 05:09

1 Answers1

1

Replace the code where you register the cell (you now want created in code rather than the .xib/storyboard), as follows:

libraryTable.register(UITableViewCell.self, forCellReuseIdentifier: "categoriesTableViewCell")

The line you show above registers the nib, so when it's time to create a cell you've told it its in a certain nib file. The replacement line creates a default cell programmatically, which means you need to make any modifications to it using swift code rather than the GUI approach which InterfaceBuilder provides. It is very straightforward.

Mozahler
  • 4,958
  • 6
  • 36
  • 56
  • Hi, I actually wanted to delete LibraryViewController.xib. I did not put anything on the view controller xib through the storyboard or code, so I'm not sure why I can't delete it. – Alex Jul 07 '17 at 12:45
  • You can. What is the exact error message? You must have code which references the nib. (Similar to the register nib for the cell.) is libraryviewcontroller mentioned in your code anywhere? – Mozahler Jul 07 '17 at 14:31
  • ohh I realized that I initialized `var libraryViewController = LibraryViewController(nibName: "LibraryViewController", bundle: nil)` in my `TabBarViewController`. Fixed it, thanks! – Alex Jul 08 '17 at 04:11