IOS -TextView 委托(delegate)未在页面容器 View 中调用

标签 ios iphone swift

我在 PageController 的页面容器 View 中使用了一个 textView。这是我的代码-

class pageContentView: UIViewController,UITextViewDelegate {

@IBOutlet weak var lblDetailTextt: UILabel!
@IBOutlet weak var lblDetailHeading: UILabel!
@IBOutlet weak var txtvieww: UITextView!

var strHeadingText = String()
var strText = String()
 var itemIndex: Int = 0

override func viewWillAppear(_ animated: Bool) {
    txtvieww.delegate = self
}
override func viewDidLoad() {
    super.viewDidLoad()
    //lblDetailTextt.text = strText

    lblDetailHeading.text = strHeadingText
     //self.lblDetailTextt.attributedText = self.stringFromHtml(string: strText)
    txtvieww.attributedText = self.stringFromHtml(string: strText)


    // Do any additional setup after loading the view.
}

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
    print("enabledd")
    return true
}

但是Delegate方法没有调用。有谁知道如何调用它吗?

最佳答案

检查您的 TextView 并确保其属性设置正确

"Links in text views are interactive only if the text view is selectable but noneditable. That is, if the value of the UITextViewselectable property is YES and the editable property is NO."

试试这个:

txtvieww.isEditable = false
txtvieww.isSelectable = true

关于IOS -TextView 委托(delegate)未在页面容器 View 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41762599/

相关文章:

ios - 在不引用自身的情况下获取 ClassName

iphone - iOS 开发 - 基本 3D 应用程序的 unity3d 替代方案

ios - 转换 [UInt8]?印象

ios - 如何将委托(delegate)传递的数据转换为不同的值?

ios - 自定义相机 View - 无法更改cameraLayout UIImagePicker、Swift的帧大小

ios - 尝试捕获整个应用程序

iphone - 将应用程序静态链接到我自己的自定义 obj-c 运行时有多简单?

iphone - iPad/iPhone 请停止解析我网站上的电话号码

iphone - 更改 UIAlertView 中取消按钮的位置?

ios - 导航 Controller 逻辑问题