高亮UITextView时显示inputAccessoryView。

4
我有两个文本视图作为UITableView的子视图,它们都有一个inputAccessoryView。其中一个是不可编辑的,但我仍然希望允许用户在其上高亮显示并进行复制|定义操作,另一个位于inputAccessoryView中。
问题在于当高亮显示不可编辑的textView时,input accessory view会出现...(为什么!?)就好像tableView突然成为了第一个响应者,我猜测是因为它的一个子视图已经成为了第一个响应者。问题是,我需要将这个不可编辑的textView从tableView的子视图中移除吗?还是有一种方法可以防止在其上高亮显示时弹出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;
}

你能解决这个问题吗?下面的两个解决方案都对我没用。 - Jordan H
return nil; 当涉及到的textView对我有用。如果这不是您的有效解决方案,敬请谅解。 - Magoo
2个回答

1

这对我在UITextView的子类中起作用。 Swift 4

override func becomeFirstResponder() -> Bool {
    guard isEditable else { return false }
    return super.becomeFirstResponder()
}

0

我通过添加解决了这个问题

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

    return self.accessoryView;
}

注意 显然,在某些情况下,您可能需要先手动调用非编辑textView上的resignFirstResponder,然后才能重新获取您的accessoryView。尽管如此,这仍然是相当干净的代码,并且可能会在将来帮助某些人。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接