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

Is there anything comparable to a ListBox like in C#?

Forums > Swift

@stony  

I have previously worked with C# programming on Windows and would now like to program a program natively with Xcode for macOS cocoa. However, I am missing the ListBox here. The goal is to display a few elements from an array one below the other, which I can then click on individually and then perform actions with them. There is the TableView in Xcode, but I don't need to make it complicated and working with it looks quite complicated.

With a ListBox this would be done with ListBox.add(). Maybe you can help me here.

2      

I think your best bet if you're using UIKit is to learn to use UITableView. You can learn to use it in Project 1 of the 100 days of Swift course on this website. It is a little bit complicated. But that's kind of true about everything in UIKit.

The alternative is using SwiftUI, where you can easily use List and ForEach to list the items in an array like this...

import SwiftUI

struct ContentView: View {
    var names = ["James", "Paul", "Lisa", "Frank", "Hannah", "Ashley", "Steve"]

    var body: some View {
        List {
            ForEach(names, id: \.self) { name in
                Text(name)
            }
        }
    }
}

2      

@stony  

Thanks for your tipps. Can you recommend a good and easy NSTableView tutorial for macOS to me (since UITableView is for ios)?

2      

Oh sorry, I didn't realize that you said it was for macOS. Honestly, I haven't done anything at all with MacOS myself yet. I just saw Cocoa and my mind went strait to UIKit stuff for iOS.

But I have purchased all of Paul's book bundles from this website. So, I just peeked at the first project in "Hacking with MacOS" to see if NSTableView would be mentioned in there. It is't though. It looks like he is using SwiftUI in that book as well.

So, unfortunately, I'm probably not the best person to ask for help with finding a good tutorial for that.

3      

A search engine search for NSTableView tutorial brought up the following Kodeco (Ray Wenderlich) tutorial:

macOS NSTableView Tutorial

If you prefer video, the Apple Programming YouTube channel has several videos on NSTableView, some of which appeared in search engine results.

The following article may also help:

Displaying Data in a Mac Table View

3      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your 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.