TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED Project 1 - display text when no image selected

Forums > macOS

I have completed Project 1 - StormViewer - but I want to add a small enhancement. I would like to display a text such as "Please select an image to display" on the DetailView if there is no image selected in the SourceView - at start up for example or if someone deselects the image.

Thanks for any suggestions,

ScottyNL

3      

Found the answer myself. Add an NSTextField to the DetailView and link it to the DetailViewController as an IBOutlet called commentView use the isHidden attribute of commentView to hide it when an image is selected and the isHidden attribute of imageView to unhide it (the attribute is initially set to true in the storyboard)

class DetailViewController: NSViewController {
    @IBOutlet var imageView: NSImageView!
    @IBOutlet var commentView: NSTextField!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do view setup here.
    }

    func imageSelected(name: String) {
        commentView.isHidden = true
        imageView.isHidden = false
        imageView.image = NSImage(named: name)
    }

    func noImageSelected() {
        commentView.isHidden = false
        imageView.isHidden = true
    }
}

And "unselect" an image is of course Command-Click - and then the text view reappears as a result of noImageSelected.

3      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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.