UITextView 打入中文时,输入拼音会调用 textViewDidChange: 回调的解决方案

做项目的时候需要用到UITextView
输入法设置为中文时,我想输入中文
“有”,我输入一个字母y的时候,一下回调会被调用

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

- (void)textViewDidChange:(UITextView *)textView

目前的解决方案是用以下方式做适配

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

    if (textView.text.length !=0) {

        int a = [text characterAtIndex:0];

        if( a > 0x4e00 && a < 0x9fff)

        {

            NSLog(@"汉字");//做相应适配

        }

        else

        {

            NSLog(@"english");//做相应适配

        }

    }

    returnYES;

}

如有疑问可以进IOS中高级开发群:118623167 和大家交流

posted @ 2012-11-26 20:08  super_chen  阅读(7385)  评论(5编辑  收藏  举报