2016-02-13 33 views
1

我試圖隱藏UITextView的文本,用作密碼輸入,使用點而不是實際文本。該文本視圖稱爲TV_Password。 當它爲空時,文本不應該被隱藏,應該用字符串「Password」替換secureTextEntry不隱藏我的UITextView文本

我在網絡上發現解決方案是將以下屬性更改爲true。

self.TV_Password.secureTextEntry = true 

不幸的是,這仍然不能隱藏我的文字。 我將修改移動到textViewShouldBeginEditing而不是textViewDidBeginEditing,建議有人遇到這種問題,但它仍然不起作用。 我有各種斷點告訴我的指示是真的完成,但沒有任何反應..

任何想法。?

//MARK: TextViews editing 

func textViewShouldBeginEditing(textView: UITextView) -> Bool { 
    if (textView == self.TV_Password){ 
     if (self.TV_Password.text == "Password"){ 
      //empty text 
      self.TV_Password.text = "" 
      //enable secured text 
      self.TV_Password.secureTextEntry = true 

     } 
    } 
    return true 
} 

func textViewDidEndEditing(textView: UITextView) { 
    if (textView == self.TV_Password) { 
     //if password empty 
     if (self.TV_Password.text == ""){ 
      //disable secured text 
      self.TV_Password.secureTextEntry = false 
      //fill with the word "Password" 
      self.TV_Password.text = "Password" 
     } 
    } 
} 
+1

'UITextView'沒有安全的輸入模式。 – dasdom

+1

如果您需要該功能,您將需要使用「UITextField」。 – Cole

+0

奇怪的是,Xcode知道這樣的方法和自動完成..即使對於UITextView .. 無論如何,非常感謝! – BUZZE

回答

1

答: UITextView的不具有安全進入模式,使用的UITextField代替。 非常感謝!