2012-04-10 10 views
0

NSMutableArray(以下の文字列の1つ)内のオブジェクトをランダムに選択し、ランダムに選択したオブジェクトの内容をUITextViewのコンテンツにする方法を知りたいと思います。以下は私のコードです:NSMutableArrayの内容でUITextViewを更新する

NSMutableArray *quotes = [[NSMutableArray alloc] initWithObjects: 
        @"Text 1", 
        @"Text 2", 
        @"Text 3", 
        @"Text 4", 
        @"Text 5", 
        @"Text 6", 
        @"Text 7", 
        @"Text 8", 
        @"Text 9", 
        @"Text 10", 
        nil]; 

textView.text = // And then I would like to know how to randomly select one of the objects within the quotes Array 

ありがとうございました!

+0

をしかし答えは正しいものであると完璧に動作します - しばらく待つより良い練習ですか? –

+0

ヘッドアップありがとう:) –

答えて

1

あなたはこのようなものを使用することができます

int randomIndex = arc4random() % quotes.count; 
textView.text = [quotes objectAtIndex:randomIndex]; 
関連する問題