2012-12-05 31 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

不客氣! ;-) –

相關問題