【发布时间】:2010-02-02 02:49:06
【问题描述】:
我只是在摆弄小应用程序,尝试学习 SDK 和 ObjC 2。
我正在尝试随机显示图片,但我一直在寻找不同的方法来显示图片。我已将图片上传到 SDKs 资源文件夹中。
无论如何,这是我的代码。有人可以引导我朝着正确的方向前进吗?
#import "randomViewController.h"
@implementation randomViewController
//not sure if this is the right way to do it really.
NSArray *comImage = [NSArray arrayWithObjects:
[UIImage imageNamed:@"rock.png"],
[UIImage imageNamed:@"paper.png"],
[UIImage imageNamed:@"scissors.png"],
nil];
- (IBAction) randButton {
int text = rand() % 3;
switch (text) {
case 0:
textView.text = @"Rock";
break;
case 1:
textView.text = @"Paper";
break;
case 2:
textView.text = @"Scissors";
break;
default:
break;
}
}
【问题讨论】:
-
我不明白“我一直在寻找不同的方式来显示图片”这句话。并请格式化代码。谢谢。
-
我不知道如何格式化代码,所以我把它放进去,对不起。基本上我所说的是我看到人们这样做的方式不同,我无法理解。谢谢:)