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 String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.