我在一个类中有7个方法。当我收到特定的消息时,我必须从这7种方法中随机调用一种方法。 我的示例代码:随机调用方法
-(void)poemAbcd{
UIImage *image = [UIImage imageNamed: @"abcd_bg.png"];
[backgroundImage setImage:image];
[self changeMumuPosition:80 with:220];
}
-(void)poemHumptyDumpty{
UIImage *image = [UIImage imageNamed: @"humpty_dumpty.png"];
[backgroundImage setImage:image];
[self changeMumuPosition:80 with:170];
}
-(void)poemBlackship{
UIImage *image = [UIImage imageNamed: @"black_sheep.png"];
[backgroundImage setImage:image];
[self changeMumuPosition:66 with:229];
}
-(void)poemRowRow{
UIImage *image = [UIImage imageNamed: @"boat_bg.png"];
[backgroundImage setImage:image];
[self changeMumuPosition:144 with:211];
}
-(void)poemHappy{
UIImage *image = [UIImage imageNamed: @"boat_bg.png"];
[backgroundImage setImage:image];
[self changeMumuPosition:144 with:211];
}
-(void)poemItsyBitsy{
UIImage *image = [UIImage imageNamed: @"boat_bg.png"];
[backgroundImage setImage:image];
[self changeMumuPosition:144 with:211];
}
-(void)poemTwinkleTwinkle{
UIImage *image = [UIImage imageNamed: @"twincle_twincle_little_star.png"];
[backgroundImage setImage:image];
[self changeMumuPosition:70 with:222];
}
分为以下几个方法我想从这些方法7随机调用一个方法。
-(void)poemRandom{
//Call a method randomly from those 7 methods
}
我该怎么做?先谢谢您的帮助。
这是什么意思“随机”在这里? – Bhavin 2013-05-09 06:54:47
而不是随机调用一个方法,因为他们都做同样的工作(在数据只是一些差别),可以封装数据,并随机挑选其中一组数据,以显示代替。 – nhahtdh 2013-05-09 06:58:17