UITextView使键盘永久?

时间:2013-01-14 09:24:06

标签: ios objective-c uitextview uikeyboard

我在一个用户界面中有两个UITextViews,其中一个UITextView是第一个响应者。另一个UITextView是不可编辑的。当我双击不可编辑的UITextView时,键盘会消失,我想避免这种情况。键盘应始终保持不变。

4 个答案:

答案 0 :(得分:1)

如果双击文本视图,它会显示带有剪切,复制等选项的UIMenuController。

因此,要达到您的要求,请将User Interaction属性设置为NO(False)。

希望这就是你要找的东西。

-Mrunal

答案 1 :(得分:1)

使viewController成为textView的委托,并从UITextViewDelegate方法NO

返回textViewShouldEndEditing:
- (BOOL)textViewShouldEndEditing:(UITextView *)textView {
    if (textView == self.editableTextView) {
        return NO;
    }
    return YES;
}

答案 2 :(得分:0)

这不是默认行为。为了达到您的要求,请尝试使用delagate方法shouldChangeTextInRange并使您的textview可编辑

- (void)viewDidLoad
{
    [super viewDidLoad];
    //nonEditingTextView.editable = NO; 
    //make the nonEditingTextView editable
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ( textView == nonEditingTextView ) {
        return NO;
    }
    return YES;
}

答案 3 :(得分:0)

//Firstly add the below code for keyboard notification into your viewdidload method.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keybordWillHide:) name:UIKeyboardWillHideNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keybordWillShow:) name:UIKeyboardWillShowNotification object:nil];

//Let the two textview's names be, NonEditable and Editable

//declare a flag globally
bool Appearflag;

//Then implement the two methods as follows

-(void)keybordWillHide:(NSNotification *)notification

{

    if ([NonEditable isFirstResponder] && Appearflag)
    {
        [Editable becomeFirstResponder];
    }else if ([Editable isFirstResponder])
    {
        Appearflag = NO;
    }
}

-(void)keybordWillShow:(NSNotification *)notification

{

    if ([Editable isFirstResponder])
    {
        Appearflag = YES;
    }
}