Deleting a line of text on an NSTextView
I have a NSTextView called TheTextView
. I'm adding there lines of text, each line representing a full path to a file with a \n
at the end. The textview is set to not editable
. I add or remove text via a +
and -
buttons.
Supposedly the user can select a line and delete it. I've tried with
[TheTextView delete:nil];
But nothing happens. How can I delete the selected line? And while we are in this topic, is there any way to set the TextView to select the whole line when I click on one line?
Thanks
EDIT:
OK, so I found that if I do the following
[TheTextVi开发者_Python百科ew setEditable:YES];
[TheTextView delete:nil];
[TheTextView setEditable:NO];
then it works. Now I need to know how to select the entire line when the user click it because otherwise it will leave a blank space in between the two lines where the one deleted was. Ideas?
It sounds like no text is selected when you call [TheTextView delete:nil]
. Try calling setSelectedRange:
with a range to select a line of text, then try calling delete:
. For example:
[TheTextView setSelectedRange:NSMakeRange(0,24)];
[TheTextView delete:nil];
Of course, you'll need to determine the correct start and length of your range to correspond the text you want to delete.
精彩评论