1.原理在创建控件时候设置特定的tag ,viewWithTag 会从self.view 逐级往下搜索找到对应的tag 并返回控件对应的类型 ,搜索不到返回nil。
创建view
for (int i = 0; i < 100; i++)
{
//row and column
//行
int row = i/3;
//列
int colume = i%3;
//创建子视图
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRECTMake(10+colume*100,10+row*100,90,90)];
imageView.Tag = 100+i;
[self.vew addSubview:imageView];
}
根据tag移除view
for (int i=0; i < 100; i++)
{
//根据tag找到对应的view
UIImageView *imgView = [self.view viewWithTag:100+i];
//移除对应的view
[imgView removeFromSuperview];
}
本文详细介绍了如何在iOS开发中利用viewWithTag方法通过tag来管理和移除视图,通过实例展示了具体操作过程,帮助开发者提高代码效率。

被折叠的 条评论
为什么被折叠?



