UITextView委托方法未使用Swift调用UITableViewCell

问题描述

我正在尝试将特定文本作为链接,并且除我的链接文本未调用委托方法并且在长按应用程序上崩溃外,其他所有内容都正常运行。

即使我在其他控制器中执行了相同的功能,我也清楚地做了所有事情,它可以完美运行,但不能在我的其他控制器中工作。

我需要一些指导,例如可能我没有足够的信息。

class MobileLoadBundleCell: UITableViewCell,UITextViewDelegate {

//MARK: - IBOutlet

@IBOutlet weak var txtDescription: UITextView!

//MARK: - Variable

let urlApp = URL(string: "link")

override func awakeFromNib() {
    super.awakeFromNib()
    
    if self.reuseIdentifier == "BalanceCell" {
        self.txtDescription.delegate = self
    }
}

func configCell() {
    
    let str = "Check your remaining usage details from my app"
    let attributedString = NSMutableAttributedString(string: str)
    let foundRange = attributedString.mutableString.range(of: "my app")
    attributedString.addAttribute(.link,value: "my app",range: foundRange)
    
    let linkAttributes: [NSAttributedString.Key : Any] = [
        .foregroundColor: UIColor(named: "ColorSetPink")!,.underlineColor: UIColor(named: "ColorSetPink")!,.underlinestyle: NSUnderlinestyle.single.rawValue
    ]
    
    self.txtDescription.linkTextAttributes = linkAttributes
    self.txtDescription.attributedText = attributedString
}

func textView(_ textView: UITextView,shouldInteractWith URL: URL,in characterRange: NSRange,interaction: UITextItemInteraction) -> Bool {
    
    if (URL.absoluteString == "my app") {
        if let url = urlApp {
            UIApplication.shared.open(url)
        }
    }
    return false
}

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)