为什么使用viewWithTag来访问Subview

简介:

在UITableViewCell里面,我们可以通过viewWithTag方法来访问Subview,这是一种快速但是比较邋遢的方式。这种方法的好处是可以快速的访问一堆连号的控件(subview),而不需要一个个的通过Ctrl drag来设置IBOutlet。下面是根据NSMutableArray设置UI的代码,好用。

int i = 0;

    for(id number in draw.primaryNumbers){

        UILabel *n = (UILabel *)[cell viewWithTag:300+i];

        // NSLog(@"%@", n);

        n.text = number;

        

        NSString* imageFile = [NSString stringWithFormat:@"Images/ball.png"];

        UIImageView * imageBall = (UIImageView *)[cell viewWithTag:200 + i];

        imageBall.image = [UIImage imageNamed:imageFile];

        ++i;

    }



    本文转自Jake Lin博客园博客,原文链接:http://www.cnblogs.com/procoder/archive/2012/12/29/Why-use-viewWithTag.html,如需转载请自行联系原作者

相关文章
|
Android开发
UIWebView添加头部视图UIView
一开始是想到在用个scollview里面嵌入一个头部view,然后在头部view下面在嵌入一个webview。
148 0
|
开发工具
UIView的clipsTobounds属性
UIView的clipsTobounds属性
101 0
UIView的clipsTobounds属性
|
容器
UIView与CALayer的关系
UIView与CALayer的关系
434 0