user500
user500

Reputation: 4519

UITableViewCell selection over UITextView

I get stuck with my cell selection. I have custom cell with UITextView object embedded in. It is not editable, not scrollable, with user interaction enabled. And I can not select cell over this view.

I've tried the same thing but with UITextField object and selection works.

Any ideas how to make it work?

This is the test project. There is just one table view with one cell. There is one text view and one text field in this cell. You can select the cell over the text field and can not over the text view.

Upvotes: 4

Views: 1760

Answers (3)

Simon Pickup
Simon Pickup

Reputation: 892

The equivalent of John's answer for Storyboards for programmatic solution is:

textView.isUserInteractionEnabled = false

Upvotes: 0

Heath Borders
Heath Borders

Reputation: 32117

Just to expound a bit on John Stephen's answer (which is the best as far as I can tell).

I've tried this by subclassing UITextView and overriding canBecomeFirstResponder:

@interface MyTextView : UITextView

@end

@implementation MyTextView

- (BOOL)canBecomeFirstResponder {
  return NO;
}

@end

I've also set editable, selectable, and scrollEnabled to NO:

MyTextView *textView = [MyTextView new];
textView.editable = NO;
textView.selectable = NO;
textView.scrollEnabled = NO;

None of these worked. :(

Upvotes: 0

John Stephen
John Stephen

Reputation: 7734

Turn off "User Interaction Enabled" on your text view and the selection will work fine (MainStoryboard.storyboard->Table View Controller->Table View->Table View Section->Custom Table View Cell->Text View). Allowing user interaction on the text view is capturing the taps before the table view cell gets them. Since your text view isn't scrollable or editable, you don't want user interaction enabled.

Upvotes: 4

Related Questions