简体   繁体   中英

Accessing a NSTableviews custom Tablecellview

I made a NSTableview and a custom tablecellview-class "KSTablecellview" which defines the cells inside the tableview.

Now I'm trying to access these cells and the elements inside them at a certain time, for example triggered through an users input.

For example I wanna change the text of a textfield in one of my custom cellviews. I tried that:

Outlet_TableView.selectRowIndexes(IndexSet(integer: 0), byExtendingSelection: false) // Selecting row #1

let view = Outlet_TableView.view(atColumn: 0, row: 0, makeIfNecessary: false) as! KSTableCellView // getting cellview, at first row/ first column (-> crashes)    
view.myTextField.stringvalue = "Hello World"

This fails giving me "[...] [default] Unable to load Info.plist exceptions (eGPUOverrides)"

I tried some other things and tried to work out the problems reason, but I wasn't able to do it, I'm still a beginner.

Any help would be really great.

I'm using XCode and Swift, trying to build an app for Mac OS.

You should try to avoid updating the content of your cells manually. Instead, you should reload the data from your data source.

func reloadData(forRowIndexes rowIndexes: IndexSet, 
                           columnIndexes: IndexSet)

Which will in turn fetch the data from your data source at the given index/column.

For example, your data source would probably contain "Hello World" at the given index after the user event occurred (provided you updated your data source content), and would thus be used in the dataCellFor: delegate method.

May be you're doing these operations before table is loaded for the first time(eg. in viewDidLoad ) or on tableView with numberOfRows = 0 .

Until tableView loads that row, it won't create the views inside that row and tableView.view(atColumn:, row:, makeIfNecessary: false) will return nil and force unwrapping this nil will make your application crash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM