NSTableView not updating on initial loading












0















I have an NSView with a NSTableView called personTableView. In the ViewController class, I have the following code:



override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
personTableView.delegate = self
personTableView.dataSource = self
personTableView.reloadData()

}


and have extended the class to with NSTableViewDelegate and NSTableViewDataSource



However, when the view appears, the table shows the following (there are only 2 entries that the table should display):



enter image description here



On my window, I have a button which invokes the following action:



@IBAction func refreshButton(_ sender: NSButton) {
let result = CoreDataHandler.fetchCount()
print("Row Count:(result)")
personTableView.reloadData()
codeTableView.reloadData()
}


which when pressed, populates my TableView. I don't understand why it won't load automatically?



I have also tried putting the personTableView.reloadData() into viewWillAppear and viewDidAppear to no avail.



Update:



This is the fetchCount():



static func fetchCount() -> Int {
let context = getContext()
do {
let count = try context.count(for: Person.fetchRequest())
NSLog("Count from fetchCount: %d", count)
return count
} catch {
return 0
}
}


For information, this is the Table Delegate and DataSource functions:



extension ViewController: NSTableViewDataSource {
func numberOfRows(in tableView: NSTableView) -> Int {
if tableView == self.personTableView {
let result = CoreDataHandler.fetchCount()
//NSLog("Rows in Ext: %@",result)
return result
}
if tableView == self.codeTableView {
let row = personTableView.selectedRow
if row > -1 {
let person = CoreDataHandler.fetchPerson()?[row]
print("Person= (String(describing: person?.first))")
//let result = CoreDataHandler.fetchCodes(person: person!)
let result = person?.codes
//print("Person from result: (String(describing: result?.first.whosAccount?.ibAccount))")
let count = result!.count
print("Rows in Codes from viewController dataSource: (count)")
return count
} else {
return 0
}
}
return 0
}
}

extension ViewController: NSTableViewDelegate {

func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {

if tableView == self.personTableView {
guard let person = CoreDataHandler.fetchPerson()?[row] else {
return nil
}

if let cell = tableView.makeView(withIdentifier: (tableColumn!.identifier), owner: nil) as? NSTableCellView {
if tableColumn == tableView.tableColumns[0] {
cell.textField?.stringValue = (person.first ?? nil) ?? ""
} else if tableColumn == tableView.tableColumns[1] {
cell.textField?.stringValue = (person.last ?? nil) ?? ""
} else {
cell.textField?.stringValue = (person.ibAccount ?? nil) ?? ""
}

return cell

} else {
return nil
}
}

if tableView == self.codeTableView {

let personRow = personTableView.selectedRow
if personRow > -1 {
let person = CoreDataHandler.fetchPerson()?[personRow]
guard let code = CoreDataHandler.fetchCodes(person: person!)?[row] else {
return nil
}

if let cell = tableView.makeView(withIdentifier: (tableColumn!.identifier), owner: nil) as? NSTableCellView {
if tableColumn == tableView.tableColumns[0] {
cell.textField?.stringValue = (String(code.number) )
//cell.textField?.stringValue = person?.codes?.allObjects[row] as! String
} else if tableColumn == tableView.tableColumns[1] {
cell.textField?.stringValue = code.code!

} else if tableColumn == tableView.tableColumns[2] {
cell.textField?.stringValue = (code.whosAccount?.ibAccount ?? "")
}

return cell

} else {
return nil
}
}
}

return nil

}



}









share|improve this question

























  • Can you share what CoreDataHandler.fetchCount() does?

    – DionizB
    Nov 21 '18 at 16:52











  • Don't fetch anything in numberOfRows and in objectValueFor. Don't do that. It's unnecessarily expensive and inefficient. Fetch the stuff once and reload the table view or use NSFetchResultsController and Cocoa Bindings. The latter reduces your code by 2/3.

    – vadian
    Nov 21 '18 at 17:40













  • @vadian: Thanks for the suggestion. I am fairly new to this. If I fetch that data once and have nothing in numberof Rows and objectValueFor, how do the tables get updated?

    – pdoak
    Nov 21 '18 at 17:45











  • Fetch the data into a data source array var people = [Person](). Return people.count in numberOfRows and people[row] in objectValueFor. And replace (person.first ?? nil) ?? "" with person.first ?? "". The second nil-coalescing operator is redundant.

    – vadian
    Nov 21 '18 at 17:46













  • @vadian: Okay but how do I return the array[row] in objectValueFor as I thought I had to return each column separately

    – pdoak
    Nov 21 '18 at 17:50
















0















I have an NSView with a NSTableView called personTableView. In the ViewController class, I have the following code:



override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
personTableView.delegate = self
personTableView.dataSource = self
personTableView.reloadData()

}


and have extended the class to with NSTableViewDelegate and NSTableViewDataSource



However, when the view appears, the table shows the following (there are only 2 entries that the table should display):



enter image description here



On my window, I have a button which invokes the following action:



@IBAction func refreshButton(_ sender: NSButton) {
let result = CoreDataHandler.fetchCount()
print("Row Count:(result)")
personTableView.reloadData()
codeTableView.reloadData()
}


which when pressed, populates my TableView. I don't understand why it won't load automatically?



I have also tried putting the personTableView.reloadData() into viewWillAppear and viewDidAppear to no avail.



Update:



This is the fetchCount():



static func fetchCount() -> Int {
let context = getContext()
do {
let count = try context.count(for: Person.fetchRequest())
NSLog("Count from fetchCount: %d", count)
return count
} catch {
return 0
}
}


For information, this is the Table Delegate and DataSource functions:



extension ViewController: NSTableViewDataSource {
func numberOfRows(in tableView: NSTableView) -> Int {
if tableView == self.personTableView {
let result = CoreDataHandler.fetchCount()
//NSLog("Rows in Ext: %@",result)
return result
}
if tableView == self.codeTableView {
let row = personTableView.selectedRow
if row > -1 {
let person = CoreDataHandler.fetchPerson()?[row]
print("Person= (String(describing: person?.first))")
//let result = CoreDataHandler.fetchCodes(person: person!)
let result = person?.codes
//print("Person from result: (String(describing: result?.first.whosAccount?.ibAccount))")
let count = result!.count
print("Rows in Codes from viewController dataSource: (count)")
return count
} else {
return 0
}
}
return 0
}
}

extension ViewController: NSTableViewDelegate {

func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {

if tableView == self.personTableView {
guard let person = CoreDataHandler.fetchPerson()?[row] else {
return nil
}

if let cell = tableView.makeView(withIdentifier: (tableColumn!.identifier), owner: nil) as? NSTableCellView {
if tableColumn == tableView.tableColumns[0] {
cell.textField?.stringValue = (person.first ?? nil) ?? ""
} else if tableColumn == tableView.tableColumns[1] {
cell.textField?.stringValue = (person.last ?? nil) ?? ""
} else {
cell.textField?.stringValue = (person.ibAccount ?? nil) ?? ""
}

return cell

} else {
return nil
}
}

if tableView == self.codeTableView {

let personRow = personTableView.selectedRow
if personRow > -1 {
let person = CoreDataHandler.fetchPerson()?[personRow]
guard let code = CoreDataHandler.fetchCodes(person: person!)?[row] else {
return nil
}

if let cell = tableView.makeView(withIdentifier: (tableColumn!.identifier), owner: nil) as? NSTableCellView {
if tableColumn == tableView.tableColumns[0] {
cell.textField?.stringValue = (String(code.number) )
//cell.textField?.stringValue = person?.codes?.allObjects[row] as! String
} else if tableColumn == tableView.tableColumns[1] {
cell.textField?.stringValue = code.code!

} else if tableColumn == tableView.tableColumns[2] {
cell.textField?.stringValue = (code.whosAccount?.ibAccount ?? "")
}

return cell

} else {
return nil
}
}
}

return nil

}



}









share|improve this question

























  • Can you share what CoreDataHandler.fetchCount() does?

    – DionizB
    Nov 21 '18 at 16:52











  • Don't fetch anything in numberOfRows and in objectValueFor. Don't do that. It's unnecessarily expensive and inefficient. Fetch the stuff once and reload the table view or use NSFetchResultsController and Cocoa Bindings. The latter reduces your code by 2/3.

    – vadian
    Nov 21 '18 at 17:40













  • @vadian: Thanks for the suggestion. I am fairly new to this. If I fetch that data once and have nothing in numberof Rows and objectValueFor, how do the tables get updated?

    – pdoak
    Nov 21 '18 at 17:45











  • Fetch the data into a data source array var people = [Person](). Return people.count in numberOfRows and people[row] in objectValueFor. And replace (person.first ?? nil) ?? "" with person.first ?? "". The second nil-coalescing operator is redundant.

    – vadian
    Nov 21 '18 at 17:46













  • @vadian: Okay but how do I return the array[row] in objectValueFor as I thought I had to return each column separately

    – pdoak
    Nov 21 '18 at 17:50














0












0








0








I have an NSView with a NSTableView called personTableView. In the ViewController class, I have the following code:



override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
personTableView.delegate = self
personTableView.dataSource = self
personTableView.reloadData()

}


and have extended the class to with NSTableViewDelegate and NSTableViewDataSource



However, when the view appears, the table shows the following (there are only 2 entries that the table should display):



enter image description here



On my window, I have a button which invokes the following action:



@IBAction func refreshButton(_ sender: NSButton) {
let result = CoreDataHandler.fetchCount()
print("Row Count:(result)")
personTableView.reloadData()
codeTableView.reloadData()
}


which when pressed, populates my TableView. I don't understand why it won't load automatically?



I have also tried putting the personTableView.reloadData() into viewWillAppear and viewDidAppear to no avail.



Update:



This is the fetchCount():



static func fetchCount() -> Int {
let context = getContext()
do {
let count = try context.count(for: Person.fetchRequest())
NSLog("Count from fetchCount: %d", count)
return count
} catch {
return 0
}
}


For information, this is the Table Delegate and DataSource functions:



extension ViewController: NSTableViewDataSource {
func numberOfRows(in tableView: NSTableView) -> Int {
if tableView == self.personTableView {
let result = CoreDataHandler.fetchCount()
//NSLog("Rows in Ext: %@",result)
return result
}
if tableView == self.codeTableView {
let row = personTableView.selectedRow
if row > -1 {
let person = CoreDataHandler.fetchPerson()?[row]
print("Person= (String(describing: person?.first))")
//let result = CoreDataHandler.fetchCodes(person: person!)
let result = person?.codes
//print("Person from result: (String(describing: result?.first.whosAccount?.ibAccount))")
let count = result!.count
print("Rows in Codes from viewController dataSource: (count)")
return count
} else {
return 0
}
}
return 0
}
}

extension ViewController: NSTableViewDelegate {

func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {

if tableView == self.personTableView {
guard let person = CoreDataHandler.fetchPerson()?[row] else {
return nil
}

if let cell = tableView.makeView(withIdentifier: (tableColumn!.identifier), owner: nil) as? NSTableCellView {
if tableColumn == tableView.tableColumns[0] {
cell.textField?.stringValue = (person.first ?? nil) ?? ""
} else if tableColumn == tableView.tableColumns[1] {
cell.textField?.stringValue = (person.last ?? nil) ?? ""
} else {
cell.textField?.stringValue = (person.ibAccount ?? nil) ?? ""
}

return cell

} else {
return nil
}
}

if tableView == self.codeTableView {

let personRow = personTableView.selectedRow
if personRow > -1 {
let person = CoreDataHandler.fetchPerson()?[personRow]
guard let code = CoreDataHandler.fetchCodes(person: person!)?[row] else {
return nil
}

if let cell = tableView.makeView(withIdentifier: (tableColumn!.identifier), owner: nil) as? NSTableCellView {
if tableColumn == tableView.tableColumns[0] {
cell.textField?.stringValue = (String(code.number) )
//cell.textField?.stringValue = person?.codes?.allObjects[row] as! String
} else if tableColumn == tableView.tableColumns[1] {
cell.textField?.stringValue = code.code!

} else if tableColumn == tableView.tableColumns[2] {
cell.textField?.stringValue = (code.whosAccount?.ibAccount ?? "")
}

return cell

} else {
return nil
}
}
}

return nil

}



}









share|improve this question
















I have an NSView with a NSTableView called personTableView. In the ViewController class, I have the following code:



override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
personTableView.delegate = self
personTableView.dataSource = self
personTableView.reloadData()

}


and have extended the class to with NSTableViewDelegate and NSTableViewDataSource



However, when the view appears, the table shows the following (there are only 2 entries that the table should display):



enter image description here



On my window, I have a button which invokes the following action:



@IBAction func refreshButton(_ sender: NSButton) {
let result = CoreDataHandler.fetchCount()
print("Row Count:(result)")
personTableView.reloadData()
codeTableView.reloadData()
}


which when pressed, populates my TableView. I don't understand why it won't load automatically?



I have also tried putting the personTableView.reloadData() into viewWillAppear and viewDidAppear to no avail.



Update:



This is the fetchCount():



static func fetchCount() -> Int {
let context = getContext()
do {
let count = try context.count(for: Person.fetchRequest())
NSLog("Count from fetchCount: %d", count)
return count
} catch {
return 0
}
}


For information, this is the Table Delegate and DataSource functions:



extension ViewController: NSTableViewDataSource {
func numberOfRows(in tableView: NSTableView) -> Int {
if tableView == self.personTableView {
let result = CoreDataHandler.fetchCount()
//NSLog("Rows in Ext: %@",result)
return result
}
if tableView == self.codeTableView {
let row = personTableView.selectedRow
if row > -1 {
let person = CoreDataHandler.fetchPerson()?[row]
print("Person= (String(describing: person?.first))")
//let result = CoreDataHandler.fetchCodes(person: person!)
let result = person?.codes
//print("Person from result: (String(describing: result?.first.whosAccount?.ibAccount))")
let count = result!.count
print("Rows in Codes from viewController dataSource: (count)")
return count
} else {
return 0
}
}
return 0
}
}

extension ViewController: NSTableViewDelegate {

func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {

if tableView == self.personTableView {
guard let person = CoreDataHandler.fetchPerson()?[row] else {
return nil
}

if let cell = tableView.makeView(withIdentifier: (tableColumn!.identifier), owner: nil) as? NSTableCellView {
if tableColumn == tableView.tableColumns[0] {
cell.textField?.stringValue = (person.first ?? nil) ?? ""
} else if tableColumn == tableView.tableColumns[1] {
cell.textField?.stringValue = (person.last ?? nil) ?? ""
} else {
cell.textField?.stringValue = (person.ibAccount ?? nil) ?? ""
}

return cell

} else {
return nil
}
}

if tableView == self.codeTableView {

let personRow = personTableView.selectedRow
if personRow > -1 {
let person = CoreDataHandler.fetchPerson()?[personRow]
guard let code = CoreDataHandler.fetchCodes(person: person!)?[row] else {
return nil
}

if let cell = tableView.makeView(withIdentifier: (tableColumn!.identifier), owner: nil) as? NSTableCellView {
if tableColumn == tableView.tableColumns[0] {
cell.textField?.stringValue = (String(code.number) )
//cell.textField?.stringValue = person?.codes?.allObjects[row] as! String
} else if tableColumn == tableView.tableColumns[1] {
cell.textField?.stringValue = code.code!

} else if tableColumn == tableView.tableColumns[2] {
cell.textField?.stringValue = (code.whosAccount?.ibAccount ?? "")
}

return cell

} else {
return nil
}
}
}

return nil

}



}






swift nstableview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 9:26









wvteijlingen

8,52612544




8,52612544










asked Nov 21 '18 at 16:27









pdoakpdoak

339211




339211













  • Can you share what CoreDataHandler.fetchCount() does?

    – DionizB
    Nov 21 '18 at 16:52











  • Don't fetch anything in numberOfRows and in objectValueFor. Don't do that. It's unnecessarily expensive and inefficient. Fetch the stuff once and reload the table view or use NSFetchResultsController and Cocoa Bindings. The latter reduces your code by 2/3.

    – vadian
    Nov 21 '18 at 17:40













  • @vadian: Thanks for the suggestion. I am fairly new to this. If I fetch that data once and have nothing in numberof Rows and objectValueFor, how do the tables get updated?

    – pdoak
    Nov 21 '18 at 17:45











  • Fetch the data into a data source array var people = [Person](). Return people.count in numberOfRows and people[row] in objectValueFor. And replace (person.first ?? nil) ?? "" with person.first ?? "". The second nil-coalescing operator is redundant.

    – vadian
    Nov 21 '18 at 17:46













  • @vadian: Okay but how do I return the array[row] in objectValueFor as I thought I had to return each column separately

    – pdoak
    Nov 21 '18 at 17:50



















  • Can you share what CoreDataHandler.fetchCount() does?

    – DionizB
    Nov 21 '18 at 16:52











  • Don't fetch anything in numberOfRows and in objectValueFor. Don't do that. It's unnecessarily expensive and inefficient. Fetch the stuff once and reload the table view or use NSFetchResultsController and Cocoa Bindings. The latter reduces your code by 2/3.

    – vadian
    Nov 21 '18 at 17:40













  • @vadian: Thanks for the suggestion. I am fairly new to this. If I fetch that data once and have nothing in numberof Rows and objectValueFor, how do the tables get updated?

    – pdoak
    Nov 21 '18 at 17:45











  • Fetch the data into a data source array var people = [Person](). Return people.count in numberOfRows and people[row] in objectValueFor. And replace (person.first ?? nil) ?? "" with person.first ?? "". The second nil-coalescing operator is redundant.

    – vadian
    Nov 21 '18 at 17:46













  • @vadian: Okay but how do I return the array[row] in objectValueFor as I thought I had to return each column separately

    – pdoak
    Nov 21 '18 at 17:50

















Can you share what CoreDataHandler.fetchCount() does?

– DionizB
Nov 21 '18 at 16:52





Can you share what CoreDataHandler.fetchCount() does?

– DionizB
Nov 21 '18 at 16:52













Don't fetch anything in numberOfRows and in objectValueFor. Don't do that. It's unnecessarily expensive and inefficient. Fetch the stuff once and reload the table view or use NSFetchResultsController and Cocoa Bindings. The latter reduces your code by 2/3.

– vadian
Nov 21 '18 at 17:40







Don't fetch anything in numberOfRows and in objectValueFor. Don't do that. It's unnecessarily expensive and inefficient. Fetch the stuff once and reload the table view or use NSFetchResultsController and Cocoa Bindings. The latter reduces your code by 2/3.

– vadian
Nov 21 '18 at 17:40















@vadian: Thanks for the suggestion. I am fairly new to this. If I fetch that data once and have nothing in numberof Rows and objectValueFor, how do the tables get updated?

– pdoak
Nov 21 '18 at 17:45





@vadian: Thanks for the suggestion. I am fairly new to this. If I fetch that data once and have nothing in numberof Rows and objectValueFor, how do the tables get updated?

– pdoak
Nov 21 '18 at 17:45













Fetch the data into a data source array var people = [Person](). Return people.count in numberOfRows and people[row] in objectValueFor. And replace (person.first ?? nil) ?? "" with person.first ?? "". The second nil-coalescing operator is redundant.

– vadian
Nov 21 '18 at 17:46







Fetch the data into a data source array var people = [Person](). Return people.count in numberOfRows and people[row] in objectValueFor. And replace (person.first ?? nil) ?? "" with person.first ?? "". The second nil-coalescing operator is redundant.

– vadian
Nov 21 '18 at 17:46















@vadian: Okay but how do I return the array[row] in objectValueFor as I thought I had to return each column separately

– pdoak
Nov 21 '18 at 17:50





@vadian: Okay but how do I return the array[row] in objectValueFor as I thought I had to return each column separately

– pdoak
Nov 21 '18 at 17:50












2 Answers
2






active

oldest

votes


















0














You've mixed up tableView(_:objectValueFor:row:) of NSTableViewDataSource and tableView(_:viewFor:row:) of NSTableViewDelegate. Replace



func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any?


by



func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView?


or return strings from tableView(_:objectValueFor:row:)






share|improve this answer
























  • That works. Thank you. I don't understand why one works and the others doesn't. Is there a quick explanation?

    – pdoak
    Nov 21 '18 at 17:40











  • See tableView(:objectValueFor:row:) and tableView(:viewFor:row:). tableView(_:objectValueFor:row:) returns a value object (string, number, image) and tableView(_:viewFor:row:) returns a view. NSTableView can't turn a view into a string.

    – Willeke
    Nov 21 '18 at 18:01











  • Thank you, that makes sense.

    – pdoak
    Nov 21 '18 at 18:02



















0














It seems like the table view is being populated based on data stored in the result variable. Try making the call to let result = CoreDataHandler.fetchCount() in viewDidLoad






share|improve this answer
























  • Thanks for the suggestion but it did not solve the problem.

    – pdoak
    Nov 21 '18 at 16:48











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416501%2fnstableview-not-updating-on-initial-loading%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You've mixed up tableView(_:objectValueFor:row:) of NSTableViewDataSource and tableView(_:viewFor:row:) of NSTableViewDelegate. Replace



func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any?


by



func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView?


or return strings from tableView(_:objectValueFor:row:)






share|improve this answer
























  • That works. Thank you. I don't understand why one works and the others doesn't. Is there a quick explanation?

    – pdoak
    Nov 21 '18 at 17:40











  • See tableView(:objectValueFor:row:) and tableView(:viewFor:row:). tableView(_:objectValueFor:row:) returns a value object (string, number, image) and tableView(_:viewFor:row:) returns a view. NSTableView can't turn a view into a string.

    – Willeke
    Nov 21 '18 at 18:01











  • Thank you, that makes sense.

    – pdoak
    Nov 21 '18 at 18:02
















0














You've mixed up tableView(_:objectValueFor:row:) of NSTableViewDataSource and tableView(_:viewFor:row:) of NSTableViewDelegate. Replace



func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any?


by



func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView?


or return strings from tableView(_:objectValueFor:row:)






share|improve this answer
























  • That works. Thank you. I don't understand why one works and the others doesn't. Is there a quick explanation?

    – pdoak
    Nov 21 '18 at 17:40











  • See tableView(:objectValueFor:row:) and tableView(:viewFor:row:). tableView(_:objectValueFor:row:) returns a value object (string, number, image) and tableView(_:viewFor:row:) returns a view. NSTableView can't turn a view into a string.

    – Willeke
    Nov 21 '18 at 18:01











  • Thank you, that makes sense.

    – pdoak
    Nov 21 '18 at 18:02














0












0








0







You've mixed up tableView(_:objectValueFor:row:) of NSTableViewDataSource and tableView(_:viewFor:row:) of NSTableViewDelegate. Replace



func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any?


by



func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView?


or return strings from tableView(_:objectValueFor:row:)






share|improve this answer













You've mixed up tableView(_:objectValueFor:row:) of NSTableViewDataSource and tableView(_:viewFor:row:) of NSTableViewDelegate. Replace



func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any?


by



func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView?


or return strings from tableView(_:objectValueFor:row:)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 17:32









WillekeWilleke

7,75121024




7,75121024













  • That works. Thank you. I don't understand why one works and the others doesn't. Is there a quick explanation?

    – pdoak
    Nov 21 '18 at 17:40











  • See tableView(:objectValueFor:row:) and tableView(:viewFor:row:). tableView(_:objectValueFor:row:) returns a value object (string, number, image) and tableView(_:viewFor:row:) returns a view. NSTableView can't turn a view into a string.

    – Willeke
    Nov 21 '18 at 18:01











  • Thank you, that makes sense.

    – pdoak
    Nov 21 '18 at 18:02



















  • That works. Thank you. I don't understand why one works and the others doesn't. Is there a quick explanation?

    – pdoak
    Nov 21 '18 at 17:40











  • See tableView(:objectValueFor:row:) and tableView(:viewFor:row:). tableView(_:objectValueFor:row:) returns a value object (string, number, image) and tableView(_:viewFor:row:) returns a view. NSTableView can't turn a view into a string.

    – Willeke
    Nov 21 '18 at 18:01











  • Thank you, that makes sense.

    – pdoak
    Nov 21 '18 at 18:02

















That works. Thank you. I don't understand why one works and the others doesn't. Is there a quick explanation?

– pdoak
Nov 21 '18 at 17:40





That works. Thank you. I don't understand why one works and the others doesn't. Is there a quick explanation?

– pdoak
Nov 21 '18 at 17:40













See tableView(:objectValueFor:row:) and tableView(:viewFor:row:). tableView(_:objectValueFor:row:) returns a value object (string, number, image) and tableView(_:viewFor:row:) returns a view. NSTableView can't turn a view into a string.

– Willeke
Nov 21 '18 at 18:01





See tableView(:objectValueFor:row:) and tableView(:viewFor:row:). tableView(_:objectValueFor:row:) returns a value object (string, number, image) and tableView(_:viewFor:row:) returns a view. NSTableView can't turn a view into a string.

– Willeke
Nov 21 '18 at 18:01













Thank you, that makes sense.

– pdoak
Nov 21 '18 at 18:02





Thank you, that makes sense.

– pdoak
Nov 21 '18 at 18:02













0














It seems like the table view is being populated based on data stored in the result variable. Try making the call to let result = CoreDataHandler.fetchCount() in viewDidLoad






share|improve this answer
























  • Thanks for the suggestion but it did not solve the problem.

    – pdoak
    Nov 21 '18 at 16:48
















0














It seems like the table view is being populated based on data stored in the result variable. Try making the call to let result = CoreDataHandler.fetchCount() in viewDidLoad






share|improve this answer
























  • Thanks for the suggestion but it did not solve the problem.

    – pdoak
    Nov 21 '18 at 16:48














0












0








0







It seems like the table view is being populated based on data stored in the result variable. Try making the call to let result = CoreDataHandler.fetchCount() in viewDidLoad






share|improve this answer













It seems like the table view is being populated based on data stored in the result variable. Try making the call to let result = CoreDataHandler.fetchCount() in viewDidLoad







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 16:44









Key HoffmanKey Hoffman

94




94













  • Thanks for the suggestion but it did not solve the problem.

    – pdoak
    Nov 21 '18 at 16:48



















  • Thanks for the suggestion but it did not solve the problem.

    – pdoak
    Nov 21 '18 at 16:48

















Thanks for the suggestion but it did not solve the problem.

– pdoak
Nov 21 '18 at 16:48





Thanks for the suggestion but it did not solve the problem.

– pdoak
Nov 21 '18 at 16:48


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416501%2fnstableview-not-updating-on-initial-loading%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]