2015-04-20 45 views
0

希望有人可以幫助我將以下NSArray文本製作爲可隨機化隨機圖像而不是當前文本的圖像數組。任何幫助是極大的讚賞。Xcode顯示隨機圖像,而不是NSArray中的文本

@synthesize predictions = _predictions; 

- (NSArray *) predictions { 

    if (_predictions == nil){ 

     _predictions = [[NSArrayalloc] initWithObjects: 
      @"Today", 
      @"Tomorrow", 
      @"Some other time", nil]; 
    } 

    return_predictions; 
} 

- (NSString*) randomPrediction { 
    int random = arc4random_uniform(self.predictions.count); 
    return [self.predictions objectAtIndex:random]; 
} 

回答

0
@synthesize predictions = _predictions; 

- (NSArray *) predictions { 

if (_predictions == nil){ 

    _predictions = [[NSArray alloc] initWithObjects: 
     @"today.png", 
     @"tomorrow.png", 
     @"someothertime.png", nil]; 
} 

return_predictions; 
} 
- (NSString*) randomPrediction { 
    int random = arc4random_uniform(self.predictions.count); 
    return [self.predictions objectAtIndex:random]; 
} 

和使用這個....

UIImage myimage=[UIImage imageNamed:[self randomPrediction]]; 

這it..I希望這個答案將有助於you.Enjoy 謝謝,