1

我有两个UITextViews合一的用户界面,其中一个UITextView是第一响应者。另一个UITextView是不可编辑的。当我双击 non-editableUITextView时,键盘消失了,我想避免这种情况。他们的键盘应该永远留下。

4

4 回答 4

1

使您的 viewController 成为 textView 的委托并NOUITextViewDelegate方法返回textViewShouldEndEditing:

- (BOOL)textViewShouldEndEditing:(UITextView *)textView {
    if (textView == self.editableTextView) {
        return NO;
    }
    return YES;
}
于 2013-01-14T09:56:50.730 回答
1

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

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

希望这是您正在寻找的。

-Mrunal

于 2013-01-14T09:53:15.183 回答
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;
}
于 2013-01-14T09:46:29.813 回答
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;
    }
}
于 2013-01-14T11:49:42.377 回答