我有一个 UITableViewCell,在它的内部,我有一个带有一些文本的 UITextView,它必须保持可滚动,所以我无法删除其中的用户交互。
但问题是,当我点击屏幕时,这个单元格也必须是可选的。由于 UITextView 位于单元触摸区域的前面,我无法这样做。
我尝试将 UITapGestureRecognizer 放入单元格类内的 UITextView 中,但我不知道调用哪个方法来选择单元格,最终以主类中的 UITableView 委托(delegate) (didSelectRowAtIndexPath) 结束。
有没有人可以帮我解决这个问题,或者有其他想法可以解决这个问题?
提前致谢!
//CUSTOM CELL CODE
-(void)awakeFromNib
{
self.backgroundColor = [UIColor clearColor];
self.title.font = [UIFont fontWithName:FONT_MEDIUM size:14];
self.title.textColor = [UIColor colorWithRed:181/255.0 green:181/255.0 blue:179/255.0 alpha:1];
self.text.font = [UIFont fontWithName:FONT_LIGHT_ITA size:13];
self.text.textColor = [UIColor colorWithRed:236/255.0 green:220/255.0 blue:0/255.0 alpha:1];
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(touchAction:)];
[self.text addGestureRecognizer:tap];
}
-(void)touchAction:(UITapGestureRecognizer*)sender{
NSLog(@"Touch");
}
-(void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
}
最佳答案
你试过这种方法吗?
在不禁用 textView 的用户交互的情况下设置 UITextView 的委托(delegate),像这样实现 UITextViewDelegate 的 textViewShouldBeginEditing 方法
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
[self.tableView selectRowAtIndexPath:yourCellIndexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
return NO;
}
documentation说“当用户执行通常会启动编辑 session 的操作时, TextView 首先调用此方法以查看是否应该实际进行编辑。”
关于iOS UITextView 不允许选择 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23497386/