Dar*_*ren 46 uitableview uitextview ios ios7
我有自定义UITableViewCells包含UITextView.我在Interface Builder中打开了UITextView中的链接检测.当我第一次加载表视图时,一切似乎都在工作,但是当我在表视图中向上和向下滚动时,链接检测会搞砸.具体来说,只有常规文本(通常最初显示)的单元格显示为链接(文本视图中的所有文本都显示为蓝色并且是活动链接),并且链接指向某些文本中的对象.其他表视图单元格.例如,链接可能指向位于不同表视图单元格中的网站,或者将电子邮件发送到位于不同表格视图单元格中的地址.
看起来当表视图单元格被重用时,即使正在更新文本视图文本,链接也会以某种方式被保存.
这只发生在iOS 7,而不是iOS 6.它发生在模拟器和我的设备上.
这是代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *sectionKey = [self.orderedSectionKeys objectAtIndex:indexPath.section];
NSDictionary *infoDictionary = [[self.tableViewData objectForKey:sectionKey] objectAtIndex:indexPath.row];
static NSString *cellIdentifier = @"InfoDefaultTableViewCell";
InfoDefaultTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"InfoTableViewCells" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
cell.bodyTextView.text = [infoDictionary objectForKey:@"description"];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
有谁知道这里发生了什么,以及如何解决它?
我尝试在设置文本视图文本后添加此代码,尝试重置链接:
cell.bodyTextView.dataDetectorTypes = UIDataDetectorTypeNone;
cell.bodyTextView.dataDetectorTypes = UIDataDetectorTypeAddress | UIDataDetectorTypeLink | UIDataDetectorTypePhoneNumber;
Run Code Online (Sandbox Code Playgroud)
但它并没有改变我所看到的行为.
小智 19
这里提供的一些建议和通过提供的链接并没有帮助我解决这个问题.
我尝试设置属性文本,将文本设置为nil,将文本设置为@"".
最后,在一个不可编辑的模式下强制文本视图就可以了.准备重用
- (void)prepareForReuse
{
...
textView.editable = YES;
textView.editable = NO;
...
}
Run Code Online (Sandbox Code Playgroud)
mel*_*nmt 16
这些答案都不适用于我(iOS8,Swift),对我来说唯一有用的是首先设置文本nil
然后在前面添加一个非可见空白unicode字符的新文本(我选择了\u200B
,这是ZERO WIDTH空格字符,但任何角色都有效):
textView.text = nil
textView.text = "?\u{200B}\(newText)"
Run Code Online (Sandbox Code Playgroud)
找到了解决这个问题的更好方法.每次设置文本时都需要额外的步骤.但这肯定解决了这个问题.
_textView.selectable = NO; // set it to NO clears all possible data detection work so far.
_textView.selectable = YES; // set it to YES so that actual links are detected.
Run Code Online (Sandbox Code Playgroud)
基本上,数据检测需要将selectable
字段设置为YES才能工作.当您将其设置为NO时,将其完全删除.
注意:这仅适用于ios7.
归档时间: |
|
查看次数: |
14352 次 |
最近记录: |