iOS 7 中 UITableView 链接检测错误中的 UITextViews [英] UITextViews in a UITableView link detection bug in iOS 7

查看:17
本文介绍了iOS 7 中 UITableView 链接检测错误中的 UITextViews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包含 UITextView 的自定义 UITableViewCells.我在界面生成器中打开了 UITextView 中的链接检测.当我第一次加载表格视图时,一切似乎都在工作,但是当我上下滚动表格视图时,链接检测变得一团糟.具体来说,只有常规文本(最初通常显示)的单元格显示为链接(文本视图中的所有文本都为蓝色并且是活动链接),并且链接指向某些其他表格视图单元格.例如,链接可能指向位于不同表格视图单元格中的网站,或者向位于不同表格视图单元格中的地址发送电子邮件.

I have custom UITableViewCells that contain a UITextView. I have link detection in the UITextView turned on in Interface Builder. When I first load the table view, everything seems to be working, but as I scroll up and down the table view, the link detection gets messed up. Specifically, cells that just have regular text (which are presented normally initially) are being shown as links (all the text in the text view is coloured blue and is an active link), and the links point to objects that are in some of the other table view cells. For example a link might point to a website that was in a different table view cell, or launch an email to an address that was in a different table view cell.

似乎当表格视图单元格被重用时,即使文本视图文本正在更新,链接也会以某种方式被保存.

It seems like when the table view cells are being reused, even though the text view text is being updated, the links are somehow getting saved.

这只发生在 iOS 7,而不是 iOS 6.它发生在模拟器和我的设备上.

This only happens in iOS 7, not iOS 6. It happens in the simulator and on my device.

代码如下:

- (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;
}

有谁知道这里发生了什么,以及如何解决它?

Does anyone know what is happening here, and how to solve it?

我尝试在设置文本视图文本后添加此代码,以尝试重置链接:

I tried adding this code after setting the text view text, to try to reset the links:

cell.bodyTextView.dataDetectorTypes = UIDataDetectorTypeNone;
cell.bodyTextView.dataDetectorTypes = UIDataDetectorTypeAddress | UIDataDetectorTypeLink | UIDataDetectorTypePhoneNumber;

但它并没有改变我所看到的行为.

but it didn't change the behaviour that I'm seeing.

推荐答案

这似乎是 iOS 7.0 的 UITextView 中的一个错误.similar question 有一个似乎有帮助的解决方法:将文本视图的文本设置为 nil 之前将其设置为新的文本字符串.

This appears to be a bug in iOS 7.0's UITextViews. A similar question has a workaround which seems to help: set the text view's text to nil before setting it to the new text string.

这篇关于iOS 7 中 UITableView 链接检测错误中的 UITextViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆