2012-04-03 45 views
-2

我在用戶點擊一個按鈕時從我的滾動視圖中動態刪除UITextFields時遇到了一些麻煩。 UITextields是以編程方式創建的。這是我迄今爲止,任何幫助,將不勝感激。正在刪除UITextField

-(IBAction)resetAll{ 

int textFieldTag; 

for (int i=0; i<[array count]; i++) { 
    textFieldTag = i + 100; 
    UITextField *myTextField = (UITextField *)[self.view viewWithTag:textFieldTag]; 
    [myTextField removeFromSuperview]; 
    [myTextField release]; 
} 
} 
+1

什麼是你的麻煩,到底是什麼?你沒有描述發生了什麼事。 – 2012-04-03 05:34:48

+0

是否要刪除特定的UITextFields或每個UITextField? - 一些更多的信息會很好。 – doge 2012-04-03 05:51:20

回答

1
-(IBAction)resetAll 
{  
    NSMutableArray *arrayTextFields=[yourScrollView subViews]; //get all subviews from your scrollview 

for (int i=0; i<[arrayTextFields count]; i++) 
{ 
    if([[arrayTextFields objectAtIndex:i] isKindOfClass:[UITextField class]]) //check for UITextField 
    { 
     UITextField *textField=(UITextField *)[arrayTextFields objectAtIndex:i]; 
     [textField removeFromSuperView]; //Remove textField 
    } 
} 
} 
0

實現此....

-(IBAction)resetAll 
{ 
    for (UITextField *myTextField in [myScrollView subviews]) 
      [myTextField removeFromSuperview]; 
} 
-1

試試這個:

-(IBAction)resetAll 
{ 
    for (UITextField *tf in myScrollView) { 
    [tf removeFromSuperview]; 
    [tf release]; 
} 

}