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

Need help getting TableView to properly display

Forums > macOS

Hello! I am working through the 1st Hacking with macOS project and have hit a pesky road block when attempting to get tableView to work in SourceViewController. I wrote the method to return number of rows but when I build the project I do not see my table. I'm not sure where I'm going wrong here but any guidance is much appreciated.

import Cocoa

class SourceViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate {
    @IBOutlet var tableView: NSTableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do view setup here.
      }
    func numberOfRows(in tableView: NSTableView) -> Int {
        return 100
    }
}

4      

Did you control-drag from the Table View to the SourceViewController in the storyboard outline? This is described on page 135 of the PDF version of the book. You have to do it twice to connect the SourceViewController to the TableView as its dataSource and its delegate.

To verify you succeeded, select the SourceViewController in the storyboard outline and press ⌥⌘7 to show the Connections Inspector. Under Referencing Outlets, tableView should be listed twice, as dataSource and delegate.

4      

Bob's answer might be the best answer of 2022 (so far) for why Obelix doesn't want to learn UIKit and Interface Builder.

3      

@bobstern

Double checked and I do have the the Source View Controller connected properly. I've attached a screenshot below. When I run my build I get a black window with an adjustable split view but no (visible) "table cell view" text indicating my table is properly loading. There is a problem somewhere but my newbie skills are making it hard to debug.

(https://drive.google.com/file/d/1SonnE7-GUqa6k38dDyIQbrOoCoQI1cm_/view?usp=sharing)

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.