I am currently wo开发者_运维百科rked on simple textview application in which I need prevent user to write data in textView & after preventing he may be change other value of textview. Below is my code for prevernting user to write into textview.
- (void)textViewDidChange:(UITextView *)textView
{
NSString *textValue=textView.text;
NSInteger intLen=[textValue length];
if(intlen>280){
textView.editable=No;
}
else
{
textView.editable=YES;
if(intLen <=140)
{
intLen=140-intLen;
intSMSValue=1;
lblSmscounter.text=[[NSNumber numberWithInt:intSMSValue]stringValue];
lblCountChar.text=[[NSNumber numberWithInt:intLen] stringValue];
}
if((intLen>140)&&(intLen <=280))
{
intLen=280-intLen;
intSMSValue=2;
lblSmscounter.text=[[NSNumber numberWithInt:intSMSValue]stringValue];
lblCountChar.text=[[NSNumber numberWithInt:intLen] stringValue];
}
}
}
But in my code I am prevent user to write more than 280 bt user caneditable the previous text.
Try delegate method
- (BOOL)textView:(UITextView )textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString)text{
}
If the range of editable text is ok, return yes.
精彩评论