问题
My method is below, it wrong works, when I write the 22222222222 to TCKimlik text field, it must be write the AdText.text = @"AYŞE"; But this method write AYŞE to TCKimlikText.And the AdText textfield shows empty. How can I solve?
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
if ([[TCKimlikText.text stringByReplacingCharactersInRange:range withString:string] isEqual:@"22222222222"])
{
cinsiyetBtn.titleLabel.text = @"BAYAN";
AdText.text = @"AYŞE";
uyrukBtn.titleLabel.text = @"TC";
babaAdiText.text = @"KEMAL";
anneAdiText.text = @"ZELİHA";
soyadiText.text = @"AYDIN";
anneKizlikSoyadiText.text = @"DEMİRCİ";
dogumTarihiText.text = @"01/01/1963";
medeniDurumBtn.titleLabel.text = @"EVLİ";
//EsinizinAdiText.text = @"AYŞE";
dogumYeriBtn.titleLabel.text = @"BURSA";
kimlikBtn.titleLabel.text = @"Nüfus Cüzdanı";
//KimlikVerilisNedeniText.text = @"YENİLEME";
//KimlikVerilisTarihi.text = @"12/01/2010";
kimlikSeriNoText.text = @"57689";
vergiKimlikNoText.text = @"45678";
kimlikSiraNoText.text = @"5443126274";
yakinlikBtn.titleLabel.text = @"EŞİ";
kizlikSoyadiText.text = @"YILMAZ";
}
return YES;
}
回答1:
Have you tested whether your code within the if-clause gets called at all? If so, check the properties of the XIB-file, maybe the connections between the xib and the code is broken (not linked). Otherwise, try:
if ([[TCKimlikText.text stringByReplacingCharactersInRange:range withString:string] isEqual:@"22222222222"])
{
NSLog("Success");
// Rest of your code...
}
to see if your statement is correct. Hope this helps!
来源:https://stackoverflow.com/questions/9019086/shouldchangecharactersinrange-method-not-work-in-objective-c