按代码

时间:2016-10-02 06:33:55

标签: ios swift tableview uisearchbar placeholder

我正在尝试在viewDidLoad中使用此代码将搜索占位符更改为表格视图中的“搜索设备”:

  let placeholderAttributes: [String : AnyObject] = [NSForegroundColorAttributeName: UIColor.blue, NSFontAttributeName: UIFont.systemFont(ofSize: UIFont.systemFontSize)]
        let attributedPlaceholder: NSAttributedString = NSAttributedString(string: "Search for a Device", attributes: placeholderAttributes)
        let textFieldPlaceHolder = searchBar.value(forKey: "searchField") as? UITextField
        textFieldPlaceHolder?.attributedPlaceholder = attributedPlaceholder

我确定代码中的一切都正常,但为什么占位符没有改变?!

1 个答案:

答案 0 :(得分:0)

您的代码运行正常,请尝试将代码段删除到viewDidLoad