How does the methods “shouldChangeTextInRange” and “stringByReplacingCharactersInRange” work?
问题 I would like to know the working of the following code. - (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string]; return !([newString length] > 10); } What does "stringByReplacingCharactersInRange" do? And how does the above method limit the number of characters that can be entered in the textField? Thanks in advance! 回答1: