我使用NSTextView为用户键入他们的响应。我已经打开了连续的拼写检查,不正确的单词下面有一条红线。我有一个共享的SpellChecker,我正在使用。但我希望用户做一个右键点击和纠正拼写。我有以下问题-
变量t= Menu.ItemArray;
先期( t)
{
var menuItem = s.CastAs();//exception
}
我基本上是试着让个人的NSMenuItem检查它是否拼写建议或其他什么。
编辑添加堆栈跟踪
System.InvalidCastException: Cannot cast from source type to destination type.
at example.test.MacOS.UI.HTML.ESView.MenuForEvent (Monobjc.Cocoa.NSEvent theEvent) [0x00000] in <filename unknown>:0
at Monobjc.Dynamic.Proxies.example.test.MacOS.UI.HTML.ESView.MenuForEvent_Monobjc_Cocoa_NSEvent (IntPtr receiver, IntPtr selector, IntPtr ) [0x00000] in <filename unknown>:0
at (wrapper native-to-managed) Monobjc.Dynamic.Proxies.example.test.MacOS.UI.HTML.ESView:MenuForEvent_Monobjc_Cocoa_NSEvent (intptr,intptr,intptr)
at (wrapper managed-to-native) E5EEC20A:pinvoke (intptr,intptr,intptr)
at E5EEC20A.objc_msgSendSuper (IntPtr receiver, IntPtr selector, System.Object[] parameters) [0x00000] in <filename unknown>:0
at Monobjc.Bridge.Generators.DynamicMessagingGenerator.SendMessage (System.String message, IntPtr receiver, IntPtr selector, System.Object[] parameters) [0x00000] in <filename unknown>:0
at Monobjc.ObjectiveCRuntime.SendMessageSuper (IManagedWrapper receiver, Monobjc.Class cls, System.String selector, System.Object[] parameters) [0x00000] in <filename unknown>:0
at Monobjc.Id.SendMessageSuper (Monobjc.Class cls, System.String selector, System.Object[] parameters) [0x00000] in <filename unknown>:0
at example.test.MacOS.UI.App.Application.SendEvent (Monobjc.Cocoa.NSEvent theEvent) [0x00000] in <filename unknown>:0
at Monobjc.Dynamic.Proxies.example.test.MacOS.UI.App.Application.SendEvent_Monobjc_Cocoa_NSEvent (IntPtr receiver, IntPtr selector, IntPtr ) [0x00000] in <filename unknown>:0
at (wrapper native-to-managed) Monobjc.Dynamic.Proxies.example.test.MacOS.UI.App.Application:SendEvent_Monobjc_Cocoa_NSEvent (intptr,intptr,intptr)
at (wrapper managed-to-native) Monobjc.ObjectiveCRuntime:objc_msgSend (intptr,intptr)
at Monobjc.ObjectiveCRuntime.SendMessage (IManagedWrapper receiver, System.String selector) [0x00000] in <filename unknown>:0
at Monobjc.Cocoa.NSApplication.Run () [0x00000] in <filename unknown>:0
at example.test.MacOS.UI.App.Application.RunApplication () [0x00000] in <filename unknown>:0
at example.test.MacOS.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 编辑-步骤3
问题3以洛朗的建议为基础。
发布于 2011-06-01 07:13:01
(第1点)
NSTextView.SelectedRange返回第一个选定的范围。如果没有选择文本,则范围的长度为0,区域的位置是光标所在的字符的索引。NSTextView.TextStorage.String)的引用,并在光标位置前后搜索空格。NSTextView.SelectedRange指定新的选择范围.(第2点)
右键单击时返回的菜单实例有一个完全控制.因此,如果您添加项目到它,您必须删除他们自己。
(关于第3点)
看上去像个虫子。正如注释中提到的,在索引循环中使用NumberOfItems和ItemAtIndex方法。
https://stackoverflow.com/questions/6189413
复制相似问题