当我们在 for 循环中创建 Button 框架时,现在我们想要删除或清理按钮框架,那么该怎么做呢?
for(int i=0 ;i<(self.WebService->ptr1).count ;i++)
{
Test1=[[UIButton alloc]initWithFrame:CGRectMake(x,y,w,h)];
[Test1 addTarget:self action:@selector(TestDescription1:)forControlEvents:UIControlEventTouchUpInside];
Test1.tag=i;
NSLog(@"test =%d",Test1.tag);
NSString *s1 =[NSString stringWithFormat:@"%@",[[self.WebService->ptr1 objectAtIndex:i]valueForKey:@"Description"]];
NSLog(@"s1 =%@",s1);
NSString *s2 =[NSString stringWithFormat:@"%@",[[self.WebService->ptr1 objectAtIndex:i]valueForKey:@"TestId"]];
NSLog(@"s2 =%@",s2);
[TestID addObject:s2];
NSLog(@"test id=%@",TestID);
[Test1 setTitle:s1 forState:UIControlStateNormal];
[scrollview addSubview:Test1];
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TestDescription1:)];
[Test1 addGestureRecognizer:tap];
Test1.userInteractionEnabled=YES;
tap.numberOfTapsRequired = 1;
y=y+40;
}
然后现在删除按钮框架,当我们想再次开始 for 循环 ....在这种情况下,如果 ARRYA.count 为 4,则设置 4 帧,但我们希望下次 Arrya.count 为 2,但最后一帧不是删除.. ..有什么解决办法?