【问题标题】:Set multiple links in UITextView within a UITableViewCell在 UITableViewCell 内的 UITextView 中设置多个链接
【发布时间】:2016-09-07 18:13:15
【问题描述】:

我有一个表格视图,可以在同一个单元格中显示多个地址以及其他一些信息。经过大量的修补和谷歌搜索,我得出结论,UITextView 是检测链接的最佳/最简单的方法。

但是,我目前使用 UITextView 的方法没有检测到链接,我不知道为什么。

这里是:

    public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
        UITableViewCell cell = tableView.DequeueReusableCell(Identifier);
        if (cell == null)
            cell = new UITableViewCell(UITableViewCellStyle.Value1, Identifier);

        cell.TextLabel.Lines = 0; // allow wrapping
        cell.TextLabel.Text = items[indexPath.Row];
        UITextView tv = new UITextView(new CoreGraphics.CGRect(cell.Bounds.X, cell.Bounds.Y, cell.ContentView.Frame.Size.Width, cell.ContentView.Frame.Size.Height));
        tv.Text = cell.TextLabel.Text;
        cell.TextLabel.Text = "";
        tv.DataDetectorTypes = UIDataDetectorType.Address;
        tv.Selectable = true;
        tv.UserInteractionEnabled = true;
        tv.ScrollEnabled = false;

        cell.ContentView.AddSubview(tv);
        return cell;
    }

这既不会检测嵌入的地址,也不允许点击它。

在这方面工作太久了,在 Android 上花了大约 3 分钟!为什么这么难??

【问题讨论】:

    标签: ios uitableview xamarin.ios uitextview


    【解决方案1】:

    替换下一行

      tv.DataDetectorTypes = UIDataDetectorType.Address;
    

     tv.DataDetectorTypes = UIDataDetectorType.Link;
    

    为了检测UITextView 中的链接,您的UITextView 应该是可选的。所以请确保您的文本视图是可选择的且不可编辑的,

      tv.editable = false;
    

    【讨论】:

    • 啊,我发现了问题,我没有将tv.editable设置为false
    • 是的,我实际上只是在打字!!
    • 不错!你可以完成输入,如果你愿意,我会接受你的回答(不确定规则是什么)
    【解决方案2】:

    发现问题,需要设置

    tv.editable = false;
    

    我认为它会自动设置为 false,但事实并非如此。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-13
      • 2015-03-21
      • 2013-01-02
      相关资源
      最近更新 更多