swift - NSTableView does not call function -


i trying populate view based nstableview in macos application. have set delegate , datasource on storyboard. have added little extension language. when load view, func numberofrows called , added tableview, function build cell value never called.

i not sure have correct nstableview basic code works great ios apps. new swift , cannot seem work properly.

any advice?

extension lamanagervc: nstableviewdatasource, nstableviewdelegate {      func numberofrows(in tableview: nstableview) -> int {         print ("my activity count: \(myactivities.count)")         return myactivities.count     }      func tableview(_ tableview: nstableview, objectvaluefor tablecolumn: nstablecolumn?, row: int) -> any?{          print ("hello world")         let cell = tableview.make(withidentifier: (tablecolumn!.identifier), owner: self) as? nstablecellview         cell?.textfield?.stringvalue = myactivities[row].title         return cell     }  } 

problem

from documentation:

table​view(_:​object​value​for:​row:)​  

called table view return data object associated specified row , column.

solution

to display cells use table​view(_:​view​for:​row:​) in case:

func tableview(_ tableview: nstableview, viewfor tablecolumn: nstablecolumn?, row: int) -> nsview? {   print ("hello world")   let cell = tableview.make(withidentifier: (tablecolumn!.identifier), owner: self) as? nstablecellview   cell?.textfield?.stringvalue = myactivities[row].title   return cell } 

Comments