我的应用程序中有一个随机pic方法:
- (void)showimage
{Int randomimages = arc4random() % 6;
switch (randomimages) {
case 0:
self.rahmen.image = [UIImage imageNamed:@"1.png"];
break;
case 1:
self.rahmen.image = [UIImage imageNamed:@"2.png"];
break; ...
但是现在我想为每个随机图片显示一个特定的文本。随机图片3.png应该出现"Info for pic 3"。我该怎么做呢?有if选项吗?喜欢的东西:如果显示图片== 4标签。文本= @"PIC 4的信息"否则如果…解决方案是什么?
不需要用这些东西就像这样,
int randomimages = arc4random() % 6;//here you are getting the random number.
self.rahmen.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",randomimages]];
对于显示文本,你可以取一个包含所有标题的数组,你可以根据这个randomimages值设置标题。
label.text=[titlesArray objectAtIndex:randomimages];