【发布时间】:2017-12-18 23:00:12
【问题描述】:
使用URL.scheme,我在UITextView 的UITableViewCell 类中获得了主题标签,但我有两个问题。
首先如何从单元格类中分离出来。我没有perform segue 功能。仅在 UITableView 类中找到。
第二如何将标签名称或提及名称发送到新的UIViewController。我可以使用委托方法或通过执行 segue 发送它。但是我又将如何从单元类中分离出来。
接下来的代码写在UITableViewCell类中
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
let path = URL.absoluteString
switch URL.scheme! {
case "hash" :
let hash = path.removingPercentEncoding?.components(separatedBy: ":").last
print(hash!) // ---> Retriving tapped on hash name correctly
case "mention" :
let mention = path.removingPercentEncoding?.components(separatedBy: ":").last
print(mention!) // ---> Retriving tapped on mention name correctly
default:
print("Just a regular link \(path.removingPercentEncoding!)")
}
return true
}
【问题讨论】:
标签: swift uitableview delegates uitextview segue