【发布时间】:2013-12-15 09:23:40
【问题描述】:
我想知道如何构建具有随机背景图像的动态 UItable?例如,我有 6 张图片分别称为 back1.png、back2.png、back3.png......back6.png。
“cellForRowAtIndexPath”中要添加什么代码
我只能依次为每个单元格分配一个特定的图像,如下所示,
if(indexPath.row == 0){
newView.backgroundColor = [UIColor [UIColor colorWithPatternImage:[UIImage imageNamed:@"lightwood1.jpg"]];
}
if(indexPath.row == 1){
newView.backgroundColor = [UIColor [UIColor colorWithPatternImage:[UIImage imageNamed:@"lightwood2.jpg"]];
}
if(indexPath.row == 2){
newView.backgroundColor = [UIColor [UIColor colorWithPatternImage:[UIImage imageNamed:@"lightwood3.jpg"]];
}
但是我如何才能在 UITableView 中随机更改为无限行?
【问题讨论】:
-
[NSString stringWithFormat:@"lightwood%d",arc4random()%6]
标签: iphone ipad ios7 uitableview