我在一個類中有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