user3470987 user3470987 - 1 year ago 139
iOS Question

Set multiple links in UITextView within a UITableViewCell

I have a tableview that will display multiple addresses as well as some other info in the same cell. After lots of tinkering and googling I came to the conclusion that

is the best/easiest way to detect links.

My current approach with
, however, is not detecting links and I am not sure why.

Here it is:

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;

return cell;

This neither detects the embedded address nor allows for it to be clicked.

Been working on this for too long now, took about 3 minutes in Android! Why is this so difficult??

Answer Source

Replace below line

  tv.DataDetectorTypes = UIDataDetectorType.Address;


 tv.DataDetectorTypes = UIDataDetectorType.Link;

And for detecting link in UITextView, your UITextView should be selectable. so make sure that your textview is selectable and not editable like,

  tv.editable = false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download