Deleting a line of text on an NSTextView - objective-c

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
[TheTextView 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.

Related

Uitextview expand to right

I have a uitextview in a tableviewcell, and I would like to know, how can I get the textview to expand to the right (ie let me keep typing without making line breaks and doing the scrolling thing). thanks
For every container, just like this one, you can set the maximumNumberOfLines to 1, which will limit the number of line breaks.
you can do it simple by set max number of lines
textview.textContainer.maximumNumberOfLines=1;

Add lines of text to subtitle of Xcode UITableView

I am using master/detail template in Xcode. I can add text into the maintitle and the subtitle of the table view.
The subtitle only shows one line of text with ... at the end.
I understand that it is telling me that more text is available.
How would I have it give me 2 or maybe 3 lines of text before the ... I tried making the cell larger, but that had no affect.
I don't see any parameters that will increase the number of lines.
thanks
The default cell give you a label with just one line, if you want change it you will need to create your own custom UITableViewCell and add a label wit the number of lines you need:
Customizing UITableViewCells

UILabel object overlaps UITextfield in custom table cell after changing text property

I have specified a custom cell containing a label and a text field in a nib file.
When I change the text property of the label and adding three of those cells in a section of a table view it looks like this:
When I don't touch the text property and simply adding the cell out of the nib file "as is" it looks like this
Well there still remains the question why the textfields right edge moved, but that is not the main problem. Can somebody tell me how I have to configure the label to avoid that nasty behavior when changing the labels text?
Change the frame of your UILabels. Now it looks like they are about 280-300px wide. Change it to something less, 120 for example.
yourTextField.frame = CGRectMake(0, 0, 120, 30);
or some other numbers. Play with it.
Hope it helps
P.S. some code would be nice
Aaaah the great mysteries of autoresizingMask. Do it like this:
Resize your labels width and can always change label background to clear
yourLabel.backgroundColor=[UIColor clearColor];

How to "insert" text into UITextField?

I'm trying to insert a text into a UITextField. But by insert, I mean replacing the character at cursor position with the new one (insert button's functionality on windows).
If I manually replace the incoming string and do setText (with NO returned to shouldChangeCharactersInRange method), the cursor moves to the end of textField.
For UITextField (iOS 3.2+), try:
[textField replaceRange:[textField selectedTextRange] withText:toInsert];
You can replace the text as you have done previously and restore the position of your caret. Note that this can only be done with UITextView rather than UITextField (that would require a lot more unjustified work, unless you absolutely have to use UITextField):
NSRange selectionRange = myTextView.selectedRange;
myTextView.text = myNewText;
myTextView.selectedRange = selectionRange;
You have to note that it's a good idea to check the validity of selectionRange variable for new text - make sure that cursor position isn't greater than the new text length.

Uitableview cell text got hidden on edit Button

When i try to delete any row - while clicking the edit button - the delete button appears and the text on right side truncated from the end.
I want to compress it automatically while delete button appears.
You can try setting the textLabel property attributes to automatically truncate the middle of the string or set a smaller (minimum) font.
[[theCell textLabel] setMinimumFontSize:theSizeYouWant];
or
[[theCell textLabel] setLineBreakMode:UILineBreakModeMiddleTruncation];