shouldChangeCharactersInRange method not work in objective c

筅森魡賤 提交于 2019-12-25 06:48:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!