我對此很新,我很抱歉問這個問題。當它們發生時檢查UITextField的按鍵,使我瘋狂:-)
我想讓這個爲我的代碼工作,但只是不明白。無論我似乎做了什麼,我按下的關鍵點在NSLog中顯示。我知道'shouldChangeCharactersInRange'以這種方式工作,我已經上網並試圖測試我找到的一些解決方案。一個是:Using `textField:shouldChangeCharactersInRange:`, how do I get the text including the current typed character?但我還是不明白。
我目前的測試代碼後,我試圖得到它的工作,並改了回來:
-(BOOL) textField: (UITextField *)theTextField shouldChangeCharactersInRange: (NSRange)range replacementString: (NSString *)string {
NSLog(@"%@", MyTextField.text);
MyTextField.text = MyTextField.text;
return YES;
}
myTextField將是文本框i型成。
有人可以告訴我如何獲得這項工作,所以我可以跟蹤每個擊鍵發生時,而不是按鍵後?
迅速解決 '''FUNC文本框(文本框:的UITextField,shouldChangeCharactersInRange範圍:NSRange,replacementString字符串:字符串) - >布爾{ let newString =(textField.text as NSString).stringByReplacingCharactersInRange(range,withString:string) return true }''' – 2015-08-18 14:08:40