2012-12-05 26 views
1

我有一个文本标签,当我按下按钮时会发生变化,标签确实会随着使用数组而改变,而不是数组的值我得到数组的键。如何获取文本标签中的数组值而不是密钥

我应该怎么做才能获得这些值?

这是代码:

NSString*path = [[NSBundle mainBundle]pathForResource:@"words" ofType:@"plist"]; 
    words = [[NSMutableArray alloc]initWithContentsOfFile:path]; 
    NSString*generateRandomLabel =[NSString stringWithFormat:@"%d", arc4random_uniform([ words count])]; 
    [self.randomLabel setText:generateRandomLabel]; 
+0

嗯,等...有一个数组没有钥匙...或者你在PHP编写你的iOS应用? – 2012-12-05 14:55:21

回答

0
NSString*path = [[NSBundle mainBundle]pathForResource:@"words" ofType:@"plist"]; 
words = [[NSMutableArray alloc]initWithContentsOfFile:path]; 
NSString*generateRandomLabel = nil; 
if ([words count] >0) 
    generateRandomLabel = [NSString stringWithFormat:@"%@", [words objectAtIndex:arc4random_uniform([ words count]-1)]]; // To make sure object is not out of bounds of array add -1 
else 
    generateRandomLabel = @"No values in array"; 
[self.randomLabel setText:generateRandomLabel]; 
+0

谢谢你的帮助 – T1992

+0

不客气! ;-) –

相关问题