0
votes
  • I'm reading a data from file that is an array of NSDictionary. With each NSDictionary include a key with name "EnglishName" and a value is type of NSString. I'm get value of a NSDictionary, create new ViewController with initialization function likes : initWithName:[(NSDictionary*)oneObjectInArray objectForKey:@"EnglishName"]; Then use NavigationController to push it.
  • The first time i push it-> no problem. Then press back then do it again(click to create new ViewController and push) an error appears with inform : [__NSArrayM rangeOfString:]: unrecognized selector sent to instance 0x63509a0'. -I have checked by add a command NSLog(@"%@", [object getObjectForKey:@"EnglishName"])->error. Then i tried to read data again in didShowView function(after back). It works without any error.

Here is the code to get data from file. Too long but maybe help to solve this problem`- (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];

} `

And there is code to get NSDictionary

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

{ currentTable = tableView; [tableView deselectRowAtIndexPath:indexPath animated:YES]; NSInteger row = [indexPath row]; NSDictionary * story; 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];

}

So what is problem ? Pls help!

1

1 Answers

1
votes

You're not retaining your dictionary.

Please edit your question and add the code where your NSDictionary gets created.