以下是从文件中获取数据的代码。太长但可能有助于解决这个问题` - (void)getListStoriesAvailable { [_header removeAllObjects]; SAFE_RELEASE(saveDataFromDataFile) [storiesAvailableArray removeAllObjects]; NSString * digit = @“0123456789”; NSString * ALPHA = @“ABCDEFGHIJKLMNOPQRSTUVWXYZ”;
for (int i = 0; i < 27; i++)
{
NSMutableArray * element = [[NSMutableArray alloc] init];
[storiesAvailableArray addObject:element];
[element release];
}
NSString * path = [NSString stringWithFormat: @"%@/data.ini",documentDirectory];
if ([[NSFileManager defaultManager] fileExistsAtPath:path])
{
saveDataFromDataFile = [[NSMutableArray alloc] initWithContentsOfFile:path];
for (int i = 0; i < [saveDataFromDataFile count]; i++)
[[saveDataFromDataFile objectAtIndex:i] setObject:@"NO" forKey:@"Downloading"];
for (int i = 0; i < [saveDataFromDataFile count]; i++)
{
NSDictionary * theStory = [saveDataFromDataFile objectAtIndex:i];
NSString * word = [theStory objectForKey:@"EnglishName"];
if ([word length] == 0) continue;
NSString * firstCharacter = [[word substringToIndex: 1] uppercaseString];
NSRange range;
//The special case when the name of story start with a digit, add the story into "0-9" header and index
range = [digit rangeOfString:firstCharacter];
if (range.location != NSNotFound)
{
[[storiesAvailableArray objectAtIndex:0] addObject:theStory];
continue;
}
//Check the index of the first character
range = [ALPHA rangeOfString:firstCharacter];
if (range.location != NSNotFound)
{
[[storiesAvailableArray objectAtIndex:(range.location + 1)] addObject:theStory];
continue;
}
}
}
NSMutableArray * temp = [[NSMutableArray alloc] init];
for (int i = 0; i < [storiesAvailableArray count]; i++)
{
if ([[storiesAvailableArray objectAtIndex:i] count] != 0)
{
[_header addObject:[ALPHA_ARRAY objectAtIndex:i]];
[temp addObject:[storiesAvailableArray objectAtIndex:i]];
}
}
[storiesAvailableArray removeAllObjects];
for (int i = 0; i < [temp count]; i++)
[storiesAvailableArray addObject:[temp objectAtIndex:i]];
//storiesAvailableArray = temp;
[temp release];
} `
还有代码来获取NSDictionary
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ currentTable = tableView; [tableView deselectRowAtIndexPath:indexPath animated:YES]; NSInteger row = [indexPath row]; NSDictionary *故事; if(tableView == listStoriesAvailable)story = [[storiesAvailableArray objectAtIndex:[indexPath section]] objectAtIndex:row];
_storyDetail = [[StoryViewController alloc] initWithName:[story objectForKey:@"EnglishName"]];
[self.navigationController setDelegate:self];
[self.navigationController pushViewController:_storyDetail animated:YES];
}
那么问题是什么?请帮助!
答案 0 :(得分:1)
你没有保留你的字典。
请编辑您的问题并添加创建NSDictionary的代码。