-3

私はこのような配列を持っています。

(

2右、1、3、4

)

ちゃんと分けてほしい。このような

(

2、1、3、4

)

私はこれを試しましたが、うまくいきませんでした。

NSMutableArray * array=[self.AnswerDic objectForKey:@"first"];
NSLog(@"%@",array);
optionA.text=[[[array objectAtIndex:0]componentsSeparatedByString:@"right"]objectAtIndex:0];
optionB.text=[[[array objectAtIndex:1]componentsSeparatedByString:@"right"]objectAtIndex:1];
optionC.text=[[[array objectAtIndex:2]componentsSeparatedByString:@"right"]objectAtIndex:2];
optionD.text=[[[array objectAtIndex:3]componentsSeparatedByString:@"right"]objectAtIndex:3];

警告してください。文字列を分離するにはどうすればよいですか?

4

3 に答える 3

1

これを使って:

NSMutableArray * array=[self.AnswerDic objectForKey:@"first"];
NSLog(@"%@",array);
optionA.text=[[[array objectAtIndex:0]componentsSeparatedByString:@"right"]objectAtIndex:0];
optionB.text=[[[array objectAtIndex:1]componentsSeparatedByString:@"right"]objectAtIndex:0];
optionC.text=[[[array objectAtIndex:2]componentsSeparatedByString:@"right"]objectAtIndex:0];
optionD.text=[[[array objectAtIndex:3]componentsSeparatedByString:@"right"]objectAtIndex:0];

以下を使用すると、オブジェクトは 1 つだけになります。

optionB.text=[[[array objectAtIndex:1]componentsSeparatedByString:@"right"]objectAtIndex:1];

したがって、インデックス 1 で問題が発生します。(連続したコードには同様の問題があります)。だから使用:

optionB.text=[[[array objectAtIndex:1]componentsSeparatedByString:@"right"]objectAtIndex:0];
于 2013-09-26T06:46:43.213 に答える
0
NSMutableArray * array=[self.AnswerDic objectForKey:@"first"];
optionA.text=[[[array objectAtIndex:0]componentsSeparatedByString:@"right"]objectAtIndex:0] ;

このようにしてください

于 2013-09-26T06:22:01.630 に答える
0

それがあなたを助けることを願っています。

NSMutableArray *array=[self.AnswerDic objectForKey:@"first"];
NSMutableArray *FinalArray=[[NSMutableArray alloc] initWithCapacity:[array count]];

for(int i=0; i<[array count]; i++)
{
    [FinalArray addObject:[[(NSString *)[array objectAtIndex:i] componentsSeparatedByString:@"right"] objectAtIndex:0]];
}

NSLog(@"%@", FinalArray);
于 2013-09-26T06:22:48.133 に答える