找到你要的答案

Q:highlighting uitextview shows inputAccessoryView

Q:突出显示inputaccessoryview UITextView

I have two textviews as subviews of a UITableView with an inputAccessoryView, one that is non editable but I'd still like to allow people to highlight and use (copy | define) on and another one that's inside the inputAccessoryView.

The problem is when highlighting the non editable textView, the input accessory view appears... (why!?) as though the tableView has suddenly become the first responder, I'm guessing because one of it's subviews has become first responder. The question is, do I need to take this non editable textView out of the tableViews subviews or is there some way to suppress the inputAccessoryView popping up when it's highlighted? The latter would be preferred.

-(UITextView *)textView
{
    if (!_textView) {

        _textView = [[UITextView alloc]initWithFrame:CGRectZero];
        //_textView.delegate = self;
        _textView.font = [UIFont questionDemiBoldFontOfSize:36.0f];
        _textView.backgroundColor = [UIColor clearColor];
        _textView.editable = NO;
        _textView.scrollEnabled = NO;
        _textView.textColor = [UIColor whiteColor];
        _textView.tintColor = [UIColor whiteColor];
        _textView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin;

    }

    return _textView;
}

我有两个TextViews作为一个inputaccessoryview UITableView视图,一个是不可编辑的但是我还是想让人们强调和使用(复制|定义),另一个是在inputaccessoryview。

问题是当突出不可编辑的TextView,输入辅助视图显示…(为什么!?)好像TableView突然成了第一个响应者,我想是因为一个它的子视图已经成为第一个响应。问题是,我需要把这个不可编辑的TextView的tableviews子视图或是有一些方法来抑制inputaccessoryview出现时,它的突出?后者将是首选。

-(UITextView *)textView
{
    if (!_textView) {

        _textView = [[UITextView alloc]initWithFrame:CGRectZero];
        //_textView.delegate = self;
        _textView.font = [UIFont questionDemiBoldFontOfSize:36.0f];
        _textView.backgroundColor = [UIColor clearColor];
        _textView.editable = NO;
        _textView.scrollEnabled = NO;
        _textView.textColor = [UIColor whiteColor];
        _textView.tintColor = [UIColor whiteColor];
        _textView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin;

    }

    return _textView;
}
answer1: 回答1:

I fixed this by adding

- (UIView *)inputAccessoryView
{
    if (self.textView.isFirstResponder)
        return nil;

    return self.accessoryView;
}

note Obviously in some cases you may have to manually call resignFirstResponder on the non editing textView first before getting your accessoryView back.. still, it's fairly clean and might help someone in the future.

我修正了这个增加

- (UIView *)inputAccessoryView
{
    if (self.textView.isFirstResponder)
        return nil;

    return self.accessoryView;
}

note Obviously in some cases you may have to manually call resignFirstResponder on the non editing textView first before getting your accessoryView back.. still, it's fairly clean and might help someone in the future.

ios  objective-c  uitableview  uitextview  inputaccessoryview