0

I get his Table view nil Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value.

final class SculpturesARViewController: UIViewController {
  private func presentSheetView() {
        let sheetViewController = SculpturesSheetViewController()
        if let sheet = sheetViewController.sheetPresentationController {
            sheet.detents = [.medium(), .large()]
            sheet.selectedDetentIdentifier = .medium
            sheet.preferredCornerRadius = 20
            sheet.prefersGrabberVisible = true
        }
        present(sheetViewController, animated: true)
    }
}

final class SculpturesSheetViewController: UIViewController {

    @IBOutlet private weak var sculpturesTableView: UITableView!
    typealias DataSource = UITableViewDiffableDataSource<SculpturesSections, SculpturesRows>
    typealias Snapshot = NSDiffableDataSourceSnapshot<SculpturesSections, SculpturesRows>
     
    override func viewDidLoad() {
        super.viewDidLoad()
        setUp()
        viewModel = SculpturesSheetViewModel(sculpturesSheetService: SculpturesNetworkService(),
                                             params: SculpturesParameters(languageId: "en"))
    }

   private func setUp() {
        configureTableView()
        
        cellFactory = SculpturesCellFactory(tableView: sculpturesTableView,
                                            sculpturesViewController: self)
    }
private func configureTableView() {
        sculpturesTableView.dataSource = dataSource
        let sections: [Any] = [SummaryTableViewCell.self, Video.self, ARFeatures.self]
        sections.forEach { section in
            let nibSection = UINib(nibName: String(describing: section), bundle: Bundle(for: type(of: self)))
            sculpturesTableView.register(nibSection, forCellReuseIdentifier: "\(section)")
        }
    }

Already try to remove the outlet and connect it again, add the delegate, instantiate differently as: let sheetViewController = SculpturesSheetViewController(nibName: "SculpturesSheetViewController", bundle: nil) But when I do that I get the error: Thread 1: "Could not load NIB in bundle: 'NSBundle </private/var/containers/Bundle/Application/5C17B15E-E6CD-489B-8285-B9E96717649F/Sculptures.app> (loaded)' with name 'SculpturesSheetViewController'"

what's wrong? nothing of that works

1 Answers1

0

I can assume that your View Controller is located inside a storyboard file. In this case, you cannot initialize it this way:

let sheetViewController = SculpturesSheetViewController()

Instead, you should load it from storyboard:

let board = UIStoryboard(name: "Main", bundle: nil)
let sheetViewController = board.instantiateViewController(withIdentifier: "myVCID")

You should set myVCID in storyboard like on image.

VC ID in storyboard

HangarRash
  • 7,314
  • 5
  • 5
  • 32