每当我尝试使用rangeOfString时,它都会在UITextView中找不到成员

时间:2015-09-05 04:47:27

标签: ios swift

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var text: UITextView!

    override func viewDidLoad() {
        super.viewDidLoad()

      let boldRange = text.rangeOfString(NSLocalizedString("bold", comment: ""))
        // issue is here. 
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

每次使用rangeOfString时我都会遇到此问题,但我不知道如何解决它。

1 个答案:

答案 0 :(得分:0)

您需要访问文本视图的let boldRange = text.text.rangeOfString(NSLocalizedString("bold", comment: "")) 属性:

{{1}}