How can I make not select text for "Copy/Paste" UITextView - ios

I want to have a UITextView in my code that you can scroll up and down, but I DO NOT want to be able to:
1) Edit it.
2) Select any of the text for "Copy/Paste".
I'm able to solve 1). I just uncheck "Editable" in the Interface Builder.
But I can't for the life of me work out how to stop the user from being able to highlight and select text.
I would imagine the solution could be along the lines of inheriting a class from UITextView and overriding one of the functions. But I'm not sure which one and how. Can anyone help?
Thanks,
- Rich

Indeed, just subclass it and rewrite:
- (BOOL)canBecomeFirstResponder {
return NO;
}

Without subclassing
- (void)textViewDidChangeSelection:(UITextView *)textView {
[textView resignFirstResponder];
}

Related

Click spacebar on the keyboard programmatically

I have an issue with a resizing UITextView
It resizes correctly when user is typing and resizes incorrectly, when i set its text programmatically
with [textView setText:]
I want to set its text to blank by doing setText:#"" and then clicking the spacebar programmatically
How do i click the space bar programmatically ?
Here are screenshots of my problem
More than likely you've put code in (void)textViewDidChange:(UITextView *)textView that doesn't belong there.
The text view calls this method in response to user-initiated changes
to the text. This method is not called in response to programmatically
initiated changes.
The solution is to create a separate method that runs regardless of whether the text was changed programmatically or by the user. It will probably looks something like this.
- (void)setText:(NSString *)text {
self.myTextView.text = text;
[self updateTextViewSize];
}
- (void)textViewDidChange:(UITextView *)textView {
[self updateTextViewSize];
}
- (void)updateTextViewSize {
//sizing logic goes here
}

How can I keep the select / select all / cut / copy / paste bar from appearing when I programmatically select text in UITextField

I've got a few instances of UITextField that I've added to some cells in a UITableView. I'm using the UITextField delegate to select all text in the textfield, like so:
-(void)textFieldDidBeginEditing:(UITextField *)textField {
[textField selectAll:self];
}
The problem I'm seeing is that I don't want the selection popup to appear the first time you touch the cell. I want to be able to edit the text, so I don't want to use becomeFirstResponder.
What you need is UIMenuController and you can hide it using - (void)setMenuVisible:(BOOL)menuVisible animated:(BOOL)animated so after your [textField selectAll:self]; call the above method to hide the menu.
EDIT
After a little search on google it seems that you will need to create a subclass of UITextField and override the - (BOOL)canPerformAction:(SEL)action withSender:(id)sender and return NO from this in order to hide the UIMenuController.
I can't test this right now since I'm not at my office but you should also try the following line [UIMenuController sharedMenuController].menuVisible = NO; before you start to implement a subclass of UITextField

UITextview doesn't enter editing on touch

I'm having trouble getting my UITextView to become editable when it is touched.
I've included the following code per the Apple documentation.
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
NSLog(#"begin editing");
return YES;
}
-(BOOL)textViewShouldEndEditing:(UITextView *)textView{
NSLog(#"end editing");
return NO;
}
I"ve also read through the apple documentation and have made the textview the delegate, but it still doesn't seem to be working. I'm pretty much trying to go with the notepad affect where once you are finished editing, numbers and such are hyperlinked.
In order to have that notepad effect, where numbers and links are hyperlinked, you would need to replace your UITextView with a special CoreTextView. I'd modify something like this to your needs: https://github.com/jasarien/CoreTextHyperlinkView. So in textViewShouldEndEditing: you would populate your CoreTextHyperlinkView text with textView.text, hide the textView and show your CoreTextView. And vice versa in textViewShouldBeginEditing:.
Also, make sure you reference the <UITextViewDelegate> protocol in your header.
Remember to set your textView's delegate, otherwise those methods won't get called
self.textView.delegate = self; // assuming self is the view controller with your textView
And remember <UITextViewDelegate>

How To Stop keyBoard Appearence at click event on UITextview?

In my IPad Application i am using TextView only for Text Displaying.As i need to display a Larger Text Thats Why i am using UITextview due to its Scrolling Property instead of using UILabel.
In my application i do not need to edit Text in UITextview ,but problem for me is that when i click on Textview for scrolling the keyboard appear its hide my textview so i want that my keyboard is never appear on click event.i make a search but not find any Suitable solution.Any help will be appriated.Thanx
NEW ANSWER (previous one was not working properly)
OK so since that is not working because it disables scrolling also, you should try to:
Implement UITextFieldDelegate protocol
In your view controller add the text
#interface YourViewController () <UITextViewDelegate>
In viewDidLoad set yourself as a delegate:
yourUITextView.delegate = self;
Implement the delegate method below:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
return NO;
}
When the textview is about to edit the text, this method will be called automatically. It returns no, so the editing won't start.
It is very important that you undo the changes from the previous answers: Do not set the editable field to NO
I tried it and it's working. Hope it helps!
OLD ANSWER
when you declare the variable, or in your viewdidload method, set the editable property to NO:
yourUITextView.editable = NO;
or
[yourUITextView setEditable:NO]
That should prevent the keyboard from appearing.
Go to .XIB file and you can uncheck behavior editable or programmatically
textView.editable = NO;

How to prevent the keyboard from showing (not dismissing) on a TextView?

I would like to know how to DISABLE (not how to dismiss) the iOS keyboard in a TextView. I don`t even want the keyboard to show up when the user touches the TextView.
All of the examples I found were to make the keyboard disappear AFTER it appears.
The closest thing I got was to set textView.userInteractionEnabled = NO; but that gets rid of the scrolling as well (I want to keep the scrolling).
Thank you in advance!!
Try to implement the following method in text view's delegate:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
return NO;
}

Resources