循环创建button的button移除问题

来源:互联网 发布:阿里云ecs安装软件 编辑:程序博客网 时间:2024/05/22 06:30

  for (int i = 0; i<= [_addView.subviews count]; i++) {            //[[_addView.subviews objectAtIndex:i] removeFromSuperview];            [[_addView.subviews lastObject] removeFromSuperview];        }
意思是:[_addView.subviews count]查看view中有几个控件

 [[_addView.subviews lastObject] removeFromSuperview];
意思是 从最后一个控件开始移除 我利用循环来移除的

- (void)btnSender:(UIButton *)sender{       int brandID = 0;    for (UIButton *btn in btnArr) {        if (btn.tag == sender.tag) {                       _imageView.frame = btn.frame;            _imageView.image = [UIImage imageNamed:@"xz"];            _bid = comIDarr[brandID];            [self.addView addSubview:_imageView];            NSInteger num = btn.tag;                        _companyLabel.text = [contentO[0][num -101] objectForKey:@"caption"];                        NSLog(@"btn.tag = %ld",(long)btn.tag);                   } else {                        NSLog(@"dainjiNONONON");                             }                 brandID++;    }    }
button➕tag然后选择它的点击时间 有选中之后的imageview的添加在button上面

0 0