【问题标题】:UITextView links highlighting, but not clickable when in custom UITableViewCellUITextView 链接突出显示,但在自定义 UITableViewCell 中时不可点击
【发布时间】:2014-03-05 23:28:45
【问题描述】:

我在自定义 tableviewcell 中有这三个文本视图(层次结构的底部)。

这是他们的设置。它们会突出显示正确的内容(电话号码、地址等),但不允许我点击它们。

【问题讨论】:

  • 嗨,你能找到解决办法吗?如果可以,可以分享一下吗?谢谢

标签: ios objective-c uitableview uitextview


【解决方案1】:

您可以尝试手动创建您的文本视图吗?下面的链接可以点击:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString* cellIdentify = @"Cell";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];

if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentify];
}

UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 10, 200, 50)];
textView.text = @"12345678 http://haivl.com";
textView.dataDetectorTypes = UIDataDetectorTypeLink;
textView.editable = NO;
textView.selectable = YES;
[cell addSubview:textView];
return cell;

}

【讨论】:

  • 通过这段代码,每次重新加载表格时,都会在单元格中添加一个新的textView,而不会删除之前的。
  • 请将单元格子类化并将textview代码放入awakeFromNib
【解决方案2】:

如果我是正确的,你想与文本视图进行交互...

[ 文本视图 setUserInteractionEnabled:YES ];

如果你想让它可编辑,那么你可以这样做,

textview.editable = 是;

或者再见像这样检查可编辑

【讨论】:

    猜你喜欢
    • 2014-07-04
    • 2017-07-06
    • 2023-03-04
    • 2010-10-23
    • 2014-03-10
    • 2016-03-29
    • 2011-04-14
    • 2014-06-22
    • 1970-01-01
    相关资源
    最近更新 更多