NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Hacking with MacOS - Project1 - Cells not displaying "Hello World"

Forums > Books

Hi there! I'm working my way through Hacking With MacOS - Swift Addition, and while I'm still very early on, I think it's great!

Anyhow, I'm at the point where I just added the "tableView" method for my SourceViewController class, which just displays "Hello World" in every cell. That compiles and runs...but I still see the default "Table View Cell" in each cell instead of "Hello World". I double checked to make sure that the SourceViewController is the dataSource of TableView, and the outlet is created, so I'm not sure what's going on.

One other confusing thing in the book is that it says:

The second method we’re going to implement is the viewFor method of NSTableView. It gets called once every column in every row, and should return the view that should be shown in that slot.

But then goes on to describe implementing tableView, which happens to have an argument called viewFor. Is that a mistake or is there something more subtle I missing (I'm very new to the Swift language)

Thanks!

bobby

1      

Figured it out! I forgot to have NSTableViewDelegate in my class declaration!

2      

To answer this part of your question...

One other confusing thing in the book is that it says:

The second method we’re going to implement is the viewFor method of NSTableView. It gets called once every column in every row, and should return the view that should be shown in that slot.

But then goes on to describe implementing tableView, which happens to have an argument called viewFor. Is that a mistake or is there something more subtle I missing (I'm very new to the Swift language)

The method name isn't actually tableView, it's tableView(_:viewFor:row:). You'll see in the NSTableViewDelegate documentation that there are a lot of similar methods that all start with tableView, such as:

tableView(_:rowViewForRow:)
tableView(_:didAdd:forRow:)
tableView(_:didRemove:forRow:)
tableView(_:isGroupRow:)

and so on.

It's just kind of a shorthand to refer to them by the second parameter name, since that's the important part of the method that distinguishes them from the other delegate methods.

1      

Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

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.