.plistファイルから情報を読み取ろうとするアプリを作成しています (そこに解析されたJSONを配置します)。
ファイルフローからの読み取りはうまくいきます。辞書の配列を取得しましたが、それをテーブルビューに表示しようとすると、問題が発生します。最初のビューは正しく読み込まれますが、スクロールを開始するとアプリがクラッシュします。
#define DOCUMENTS [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *filePathDocArray = [DOCUMENTS stringByAppendingPathComponent:@"filters.plist"];
NSString *filePathBundleArray = [[NSBundle mainBundle] pathForResource:@"filters" ofType:@"plist"];
if (![[NSFileManager defaultManager] fileExistsAtPath:filePathDocArray]) {
[[NSFileManager defaultManager] copyItemAtPath:filePathBundleArray toPath:filePathDocArray error:nil];
NSLog(@"File saved");
} else {
NSLog(@"File already exists");
filters = [NSArray arrayWithContentsOfFile:filePathDocArray];
}
}
ここで、必要なすべての情報をフィルター配列に取得します (ループによってチェックされます)。それで:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [filters count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *myIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:myIdentifier];
}
NSInteger crow = indexPath.row;
NSDictionary *story = [filters objectAtIndex: crow];
cell.textLabel.text = [story objectForKey:@"Name"];
cell.detailTextLabel.text = [story objectForKey:@"Description"];
return cell;
}
@end
アプリの起動時は問題ありません: 通常のテーブル ビューが表示されますが、スクロールを開始するとクラッシュします
私が評価した一連のブレークポイント デバッグの後、アプリケーションが Simulator で起動した後、配列フィルターのリンクがネジ止めされるため、次のセルに入力しようとすると、ストーリーディクショナリが適切に作成されません。
どのような問題が考えられますか?
コンソールレポートは次のとおりです。
2012-09-22 13:37:43.545 JSONExample[4559:207] -[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x6a083c0
2012-09-22 13:37:43.547 JSONExample[4559:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x6a083c0'