オンライン フィードから一部のデータを解析し、そのデータを複数のオブジェクトに配置します。次に、オプションを表示するページを作成し、その配列内のすべての部分を表示するテーブルビューに移動します。
私が考えている問題は、10/11 オプションが問題なく動作することです。別のオプションを表示してから入力しようとすると、最後のオプションで範囲外の例外が発生します。その 11 番目のオプションが最初に入力された場合、それは正常に機能します。他のオプションを表示してからオプション ページを閉じ、そこに戻って 11 番目のオプションを表示すると、それも正常に機能します。
これは、データを領域に分類するコードです (このビットは、私が問題を抱えている部分にすぎません)。
-(void)TBSortOut {
[app.TBArray removeAllObjects];
NSLog(@"this is running");
for (int i = 200; i < app.listArray.count; i++) {
theList = [app.listArray objectAtIndex:i];
if ([theList.course rangeOfString:@"Time Based Art & Digital Film" options:NSCaseInsensitiveSearch].location == NSNotFound) {
}else{
[self sortOutArray];
[app.TBArray addObject:theList];
theList = nil;
}
}
}
テーブル内のセルを並べ替える masterViewController 内にあるコードのセクションが続きます。私の問題は次のとおりです。
- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
@try{
theList = NULL;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.shouldIndentWhileEditing = NO;
}
//selecting which array to display within the tableview
if (app.courseChoice == 11) {
theList = [app.TBArray objectAtIndex:indexPath.row];
} else if (app.courseChoice == 1) {
theList = [app.AniArray objectAtIndex:indexPath.row];
} else if (app.courseChoice == 2) {
theList = [app.APCPArray objectAtIndex:indexPath.row];
} else if (app.courseChoice == 3) {
theList = [app.DIXDArray objectAtIndex:indexPath.row];
} else if (app.courseChoice == 4) {
theList = [app.FAArray objectAtIndex:indexPath.row];
} else if (app.courseChoice == 5) {
theList = [app.GDArray objectAtIndex:indexPath.row];
} else if (app.courseChoice == 6) {
theList = [app.ILLArray objectAtIndex:indexPath.row];
} else if (app.courseChoice == 7) {
theList = [app.IEDArray objectAtIndex:indexPath.row];
} else if (app.courseChoice == {
theList = [app.JEWArray objectAtIndex:indexPath.row];
} else if (app.courseChoice == 9) {
theList = [app.PROArray objectAtIndex:indexPath.row];
} else if (app.courseChoice == 10) {
theList = [app.TEXArray objectAtIndex:indexPath.row];
}
//sets name of the cell and the type of indicator used within the cell(arrow)
cell.textLabel.text = theList.fullname;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
@catch(NSException *e){
NSLog(@"catching %@ reason %@", [e name], [e reason]);
}
}
try catch が出力しているエラーは次のとおりです。
catching NSRangeException reason *** - [_NSArrayM objectAtIndex:]: index 10 beyond bounds [0 .. 9]
コード内のさまざまなポイントで印刷を試みましたがNSLog
、前のビューが使用するビューをテーブルに伝える前にテーブルが情報をロードしようとするため、テーブルビューはより大きなテーブルをロードしようとしますロードしている配列が本来あるべき配列よりも小さいことに気付くと、エラーが発生します。
これを解決するにはどうすればよいですか?選択した配列の最後に到達した場合に実行を停止するtry
/catch
内にコードを配置する方法はありますか? if
または、問題が停止するように、アプリにオプションを指定してページを強制的にリロードさせる方法はありますか?
編集: クラッシュ前のログ。最初のセットは、テーブルビューに表示する前のオプション ページからのもので、個別の配列ごとにカウントを示します。2 番目のセットは、1 つが選択されるとアレイを表示し、コースはアプリがクラッシュするのと同じように表示されます (「(m)」は、ログがさまざまなビューから来ていることがわかるようにするためです):
2013-04-30 15:23:14.985 Degree Show 2013[5665:907] AniArray amount 17
2013-04-30 15:23:14.986 Degree Show 2013[5665:907] APCPArray amount 6
2013-04-30 15:23:14.987 Degree Show 2013[5665:907] DIXDArray amount 5
2013-04-30 15:23:14.987 Degree Show 2013[5665:907] FAArray amount 65
2013-04-30 15:23:14.988 Degree Show 2013[5665:907] GDArray amount 17
2013-04-30 15:23:14.989 Degree Show 2013[5665:907] ILLArray amount 19
2013-04-30 15:23:14.990 Degree Show 2013[5665:907] IEDArray amount 23
2013-04-30 15:23:14.990 Degree Show 2013[5665:907] JEWArray amount 20
2013-04-30 15:23:14.991 Degree Show 2013[5665:907] PROArray amount 26
2013-04-30 15:23:14.992 Degree Show 2013[5665:907] TEXArray amount 26
2013-04-30 15:23:14.992 Degree Show 2013[5665:907] TBArray amount 10
2013-04-30 15:24:31.819 Degree Show 2013[5665:907] (m)AniArray amount 17
2013-04-30 15:24:31.820 Degree Show 2013[5665:907] (m)APCPArray amount 6
2013-04-30 15:24:31.820 Degree Show 2013[5665:907] (m)DIXDArray amount 5
2013-04-30 15:24:31.821 Degree Show 2013[5665:907] (m)FAArray amount 65
2013-04-30 15:24:31.821 Degree Show 2013[5665:907] (m)GDArray amount 17
2013-04-30 15:24:31.822 Degree Show 2013[5665:907] (m)ILLArray amount 19
2013-04-30 15:24:31.823 Degree Show 2013[5665:907] (m)IEDArray amount 23
2013-04-30 15:24:31.823 Degree Show 2013[5665:907] (m)JEWArray amount 20
2013-04-30 15:24:31.824 Degree Show 2013[5665:907] (m)PROArray amount 26
2013-04-30 15:24:31.824 Degree Show 2013[5665:907] (m)TEXArray amount 26
2013-04-30 15:24:31.825 Degree Show 2013[5665:907] (m)TBArray amount 10
2013-04-30 15:24:31.829 Degree Show 2013[5665:907] (m)course choice = 11
編集 2: いくつかの開発では、クラッシュを停止している@finally
後にa を追加しましたtry/catch
が、最終ビューに余分なセルが表示されます。この数は、実際にアクセスした前の配列内のオブジェクトの数のようです。また、このテストはすべて iPhone 5 で行われました。私は iPhone 4 で試したところ、すべて完璧に動作しました。新しい iPhone で処理されるテーブルは、以前のものとは異なりますか?