IOS -TextView委托不在页面容器视图中调用

时间:2017-01-20 11:28:15

标签: ios iphone swift

我在PageController的页面容器视图中使用了一个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方法没有调用。有人知道如何调用它吗?

1 个答案:

答案 0 :(得分:2)

检查您的textview并确保其属性具有正确的设置

  

"文本视图中的链接仅在文本视图中是交互式的   可选但不可编辑。也就是说,如果是的价值   UITextViewselectable属性为YES,可编辑属性为NO。"

试试这个:

txtvieww.isEditable = false
txtvieww.isSelectable = true