我在我的视图中使用了
UITextView
,需要计算文本视图包含的行数。我使用以下函数来读取'\n'
。但是,当我连续输入字符时,不会得到新的换行符号。如何在更改行时读取新字符而无需按回车键?有没有人知道如何做...请分享一下。
我遵循这个链接 Link。- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text
{
// Any new character added is passed in as the "text" parameter
if ([text isEqualToString:@"\n"]) {
// Be sure to test for equality using the "isEqualToString" message
[textView resignFirstResponder];
// Return NO so that the final '\n' character doesn't get added
return NO;
}
// For any other character return YES so that the text gets added to the view
return YES;
}
BOOL
的两个取值不是TRUE
和FALSE
,而是YES
和NO
。 - BoltClock