Search code examples
iphoneobjective-cios5ios6

Dismiss generated UITextfields


I am generating UITextfields dynamically on a scrollview as the user enters number in the UITextfield (lets say it "A") and hits a button. But what i need to do is when user reenters number in UITextfields the previously displayed UITextfields must be gone and new UITextfields` must be generated.

for (UIView *field in self.scrollView.subviews)
{
     if([field isKindOfClass:[UITextField class]])
     [field removeFromSuperview];
}

eg- if first i generated 7 UITextfields and afterwards i edit the "A" again and put 3 as value only 3 UITextfields must be visible. but in my code the 3 UITextfields are overwritten on 7 but previous also displayed.


Solution

  • I have tried this code and this worked for me

    for (y=1;y<=Pointsvalue;y++)
    {
        UITextField *txtField =(UITextField *)[self.view viewWithTag:y+Pointsvalue];
        if (txtField.tag == y+Pointsvalue)
        {
            [txtField removeFromSuperview];
            [Feilds2Array removeAllObjects];
        }
    }