Remove correctly selected NSManagedObjects

我与影子孤独终老i 提交于 2019-12-11 17:19:55

问题


Look at this great screenshot and I think you can imagine what I could ask...

screenshot http://a4.s3.p.quickshareit.com/files/screenshot_75d0fc54a05ec7eae3f410.png The players:

to the right: the preferences-panel and a NSTableView
to the left: main-window with a NSPopUpButton (under the NSMenu ;] )

The selected object of the popup is binded to one of these in the tableview. This ugly thing (what you can see there) appears when I remove the (in the popup selected) object from the tableview. I'm using CoreData and the NSArrayController is binded to one Entity.

I found 2 interesting things:

NSManagedObjectContextObjectsDidChangeNotification  
[NSPopUpButton synchronizeTitleAndSelectedItem];

With the first I know when someone removes a item from the tableview; the second doesn't work unfortunately for my problem...

So any idea how to blast away this ugly thing? =D

By the way: If you are interested in this nice app and a native URL shortener you should look here.


回答1:


If I understand your description of how everything is built up correctly, selectedObject in your NSPopupButton is bound to some value in your NSTableView.  My guess is that you are using dataSource methods to provide the table with data, and bindings to match the data in the popup with the table.

You should probably use an NSArrayController for the actual dataset, bind its content array to an NSMutablearray in your controller, and bind both the tableView and the NSPopupButton to the arrayController, instead of binding one control to the other.  The problem you describe does not seem to have very much to do with NSManagedObject, except for seeing a default implementation of -description in this situation, but moreso with using bindings in an unconventional way.




回答2:


I have it!
I just unbinded the selected object of the NSPopUpButton and binded it again. It performs this action only when the selected object was removed from list. ;)



来源:https://stackoverflow.com/questions/543283/remove-correctly-selected-nsmanagedobjects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!