为什么使用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;

    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM