NSTableView and data validation?
In order to properly learn Objective-C and the Cocoa framework, I have started building a CoreData application, but I'm a bit at a loss on how to properly provide data validation when an item is being edited in an NSTableView.
My model has an entity called "Business" with two string properties: a name and an issued tax number. The second property must have a length of exactly 10 characters. This entity's objects are displayed and edited in an NSTableView, through an NSArrayController bound to the Business entity and the app's managedObjectContext.
What I would like to do is: - the user starts editing the tax number in the appropriate cell (NSTextFieldCell) of the tableview. - when pressing Enter, the new value is validated, ie checks to see that the new value has a length of 10 characters. If validation fails, an alert sounds and the cell keeps being focused. - pressing Escape restores the old value and the cell loses focus.
What is the proper way to perform this validation?
请参阅“核心数据编程指南”的“管理对象验证”一章。
If you are using bindings, you can check the "Validates Immediately" in the binding for cell value. That will call the validation method for the managed object.
链接地址: http://www.djcxy.com/p/85208.html上一篇: 如何从NSOutlineView中的NSTextFieldCell中剪切和粘贴文本
下一篇: NSTableView和数据验证?