UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Project 1, DetailViewController does not load (SOLVED)

Forums > 100 Days of Swift

Build completes succesfully, image names are displayed, but after click on it - nothing happens. My code:

ViewController.swift:

import UIKit

class ViewController: UITableViewController {
    var pictures = [String]()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

        let fm = FileManager.default
        let path = Bundle.main.resourcePath!
        let items = try! fm.contentsOfDirectory(atPath: path)

        for item in items {
            if item.hasPrefix("nssl") {
                pictures.append(item)
            }
        }

        print(pictures)
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return pictures.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Picture", for: indexPath)
        cell.textLabel?.text = pictures[indexPath.row]
        return cell
    }

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if let vc = storyboard?.instantiateViewController(withIdentifier: "Detail") as? DetailViewController {
            vc.selectedImage = pictures[indexPath.row]
            navigationController?.pushViewController(vc, animated: true)
        }
    }

}

DetailViewController:

import UIKit

class DetailViewController: UIViewController {

    @IBOutlet var imageView: UIImageView!

    var selectedImage: String?

    override func viewDidLoad() {
        super.viewDidLoad()

        if let imageToLoad = selectedImage {
            imageView.image = UIImage(named:imageToLoad)
        }
    }

Detail View Controller Scene has assigned custom class DetailViewController, Storyboard ID "Detail".

Builtime warning: warning: Unsupported Configuration: “Navigation Controller“ is unreachable because it has no entry points, and no identifier for runtime access via -[UIStoryboard instantiateViewControllerWithIdentifier:].

P.S. DetailViewController.swift file in project library is dimmed compared to other files. Not sure if that is relevant.

3      

Disclamer: I may be wrong, only 30 days into the course

I can assume that reason might that in "Main.storyboard" the entrypoint is aimed to the "View Controller" instead of "Navigation Controller"

That is for View Controller loaded without Navigation Controller and pushing to navigationController does nothing.

The instructions was to

  1. Make View Controller entry point
  2. Only after that to embed it into Nav Controller

If you do it in opposite direction - you may stuck with what I've described before.

If that is the case, then the solution will be: Select the Navigation Controller in "Main.storyboard" and hit the tick in front of "Is Initial View Controller", or drag the arrow to Navigation Controller.

Here is how it should look like: image.png

4      

@TD540  

I'm still stuck with this problem

I tried @gumlooter's advice, I tried clearing Derived Data, restarting Xcode... no luck.

Using Xcode 13.2 beta 2 (13C5081f)

So I installed the latest/stable Xcode 13.1 and opened Project1 in it and the problem went away. Doing this also fixed the problem in Xcode 13.2 beta 2 :)

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.