在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;
}