相关疑难解决方法(0)

如何读取UITextView中的行数

我正在使用UITextView在我的视图中,我要求使用以下函数来计算textview am所包含的行数'\n'.但是这只有在从键盘按下返回键时才起作用,但是在线条换行器中(当我键入连续字符时,我不会获得新行字符).如何在不更改返回键的情况下更改行时读取新的字符?任何人都有任何想法如何...请分享它..我正在关注此链接 链接

- (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;
}
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c uitextview

24
推荐指数
3
解决办法
3万
查看次数

标签 统计

cocoa-touch ×1

iphone ×1

objective-c ×1

uitextview ×1