Ios UITextField应更改CharactersRange方法未按预期工作

Ios UITextField应更改CharactersRange方法未按预期工作,ios,xcode,swift,uitextview,uitextviewdelegate,Ios,Xcode,Swift,Uitextview,Uitextviewdelegate,现在,当我试图修改textfield时,应该调用这个函数。当我尝试使用断点调试此代码时,首先执行步骤1,然后立即执行到步骤4。执行此操作后,返回步骤2、步骤3、步骤5,最后修改文本字段。是否不应按顺序从步骤1执行到步骤5 请参考此答案,它将帮助您将构建配置设置为发布吗?是。不确定这会有什么不同。要可靠地使用调试器,您需要将构建配置设置为Debug。 func textField(textField: UITextField, shouldChangeCharactersInRange range

现在,当我试图修改textfield时,应该调用这个函数。当我尝试使用断点调试此代码时,首先执行步骤1,然后立即执行到步骤4。执行此操作后,返回步骤2、步骤3、步骤5,最后修改文本字段。是否不应按顺序从步骤1执行到步骤5

请参考此答案,它将帮助您将构建配置设置为发布吗?是。不确定这会有什么不同。要可靠地使用调试器,您需要将构建配置设置为Debug。
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

   //step1: Figure out what the new text will be, if we return true
   var newText: NSString = textField.text
   println("test")

   //step2. 
   newText = newText.stringByReplacingCharactersInRange(range, withString: string)

    //step3: hide the label if the newText will be an empty string
    self.characterCountLabel.hidden = (newText.length == 0)

    //step4: Write the length of newText into the label
    self.characterCountLabel.text = String(newText.length)

    //step: returning true gives the text field permission to change its text
    return true;
}