我正在嘗試創建一個多選測試應用程序。我有這樣的代碼來讀出一個.txt文件:幫助分組數組索引(objectAtIndex 0 - 9)= 1索引點
filePath = [[NSBundle mainBundle] pathForResource:@"testBank" ofType:@"txt"];
theBank = [[NSString alloc] initWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding error:NULL];
multipleChoicePractice = [theBank componentsSeparatedByString:@"\n"];
的multipleChoicePractice的NSMutableArray現在包含在此爲了一堆NSString的的:
Question 1
choice A
choice B
choice C
choice D
Answer Key
Rationale
question ID 1
[string to id type of question]
[space 1]
Question 2
choice A-2
etc etc up to Question 10
我想組的每個指數的10組因此multipleChoicePractice的索引0到9是新的可變數組questionGroupArary的索引0。我想:
for (i=0; i<=90; i = i+10) { //qArr being a NSMutableArray
[qArr addObject:[multipleChoicePractice objectAtIndex:i]];
[qArr addObject:[multipleChoicePractice objectAtIndex:(i+1)]];
[qArr addObject:[multipleChoicePractice objectAtIndex:(i+2)]];
[qArr addObject:[multipleChoicePractice objectAtIndex:(i+3)]];
[qArr addObject:[multipleChoicePractice objectAtIndex:(i+4)]];
[qArr addObject:[multipleChoicePractice objectAtIndex:(i+5)]];
[qArr addObject:[multipleChoicePractice objectAtIndex:(i+6)]];
[qArr addObject:[multipleChoicePractice objectAtIndex:(i+7)]];
[qArr addObject:[multipleChoicePractice objectAtIndex:(i+8)]];
[qArr addObject:[multipleChoicePractice objectAtIndex:(i+9)]];
[questionGroupArray addObject:qArr];
}
的,對於循環的結果是,questionGroupArray objectAtIndex:0包含問題1和問題10.什麼是實現我的目標,使questionGroupArray索引0包含「問題1」,以最好的方式之間的一切「[空間1]」?我覺得有一種方法可以用for循環來做到這一點,但它逃脫了我。謝謝!
有沒有辦法把這個500萬點?非常感謝你,這很有魅力。可能會花上幾天的時間。 – JustAnotherCoder
不是我所知道的。但另一個快樂的iOS開發讓我開心。 – PeyloW