我有两个UITextView
让用户在第一个文本视图中输入一些文本并在第二个文本视图中产生一些不同的文本。
用户可以在第一个文本视图中输入下一行,但是我不希望在第二个文本视图中生成空行。我想知道如何检测第一个文本视图中是否有空行并删除这些行?
谢谢你。
字符输入计数错误的结果:
-(void)textViewDidChange:(UITextView *)textView{
if ([inputTextSection.text rangeOfString:@"\n\n"].location == NSNotFound) return;
NSString *resultStr = [inputTextSection.text stringByReplacingOccurrencesOfString:@"\n\n" withString:@"\n"];
inputTextSection.text = resultStr;
int maxChars = 70; //maximum characters
int charsLeft = maxChars - [inputTextSection.text length];
if(charsLeft == 0) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"No more characters"
message:[NSString stringWithFormat:@"You have reached the character limit of %d.",maxChars]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
liveCountTextView.text = [NSString stringWithFormat:@"%d/70",charsLeft];}