4
votes

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;
}
2
Were you able to resolve this? Neither solution below worked for me.Jordan H
return nil; when it's the textView in question did work for me. Apologies if it's not a valid solution for you..Magoo

2 Answers

1
votes

This worked for me in a UITextView subclass. Swift 4

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

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.