XCode: Get cursor positon of NSTextfield

Sometime you need the curor position of a NSTextfield e.g. to insert some text programmatically.
Therefor you can use the fieldEditor . That's a single object of NSTextView for simple text-editing needs.

To get the position of cursur you can write:

NSUInteger cursorPos = [[[_myTextfield window] fieldEditor:YES  forObject:_myTextfield] selectedRange].location;

Or if you programming inside a subclass of NSTextfield:

NSUInteger cursorPos = [[_window fieldEditor:YES  forObject:self] selectedRange].location;


comments powered by Disqus

Copyright Dunkel & Iwer GbR | Datenschutzerklärung | Impressum