开发者

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开发者_JS百科 and one text field in this cell. You can select the cell over the text field and can not over the text view.


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.


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. :(


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

textView.isUserInteractionEnabled = false
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜