Pregunta

I have a NSWindowController as part of the work flow with NSDocument. The NSWindowController has an associated xib with a couple of NSTableViews. The datasource for these tableviews is a model defined by the NSDocument. I seem to be missing some information on setting up the outlets. If I setup all the outlets within IB, the datasource(s) are created at the time the nib is instantiated with their default init methods, which don't know about the model. By the time awakeFromNib is called, the datasource has already been queried by the tableview (numberOfRowsInTableView). My work-around is to not hook up the outlets for datasource. I get the model information in setDocument and set the delegates in windowDidLoad. This seems to work. How do I pass around a data model when setting the tableview datasource with IB? Since the outlets are not created when init is called (within the tableview datasource), how would I call out to get the model?

Thanks in advance.

¿Fue útil?

Solución

There's an explicit note in the NSTabelView documentation:

Important: It’s possible that your data source methods for populating the table view may be called before awakeFromNib is called if the data source is specified in Interface Builder. You should defend against this by having the data source’s numberOfRowsInTableView: method return 0 for the number of rows when the data source has not yet been configured. In awakeFromNib, when the data source is initialized you should always call reloadData on the table view.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top