0

有时,我的应用程序在使用时会丢失所有数据:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    switch (indexPath.row)
    {
        case kLANG_HEBREW:
            // Hebrew is the default
            self.arrayOfLanguages = [NSMutableArray arrayWithObjects:@"he", @"en", nil];
            break;
        case kLANG_ENGLISH:
            self.arrayOfLanShorts = [NSMutableArray arrayWithObjects:@"en", @"he", nil];
            break;
        case kLANG_RUSSIAN:
            self.arrayOfLanShorts = [NSMutableArray arrayWithObjects:@"ru", @"en", nil];
            break;
        case kLANG_ARABIC:
            self.arrayOfLanShorts = [NSMutableArray arrayWithObjects:@"ar", @"en", nil];
            break;
    }
    [[NSUserDefaults standardUserDefaults] setObject:self.arrayOfLanShorts forKey:@"AppleLanguages"];
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"come_from_change_lang"];
    [[NSUserDefaults standardUserDefaults] synchronize];    
    [self.navigationController popToRootViewControllerAnimated:YES];
}

这很奇怪,因为我没有清除我的应用程序中的数据。

4

1 回答 1

0

我的猜测是你的 switch 语句并不总是设置self.arrayOfLanShorts,然后它是零。然后,当您在我们的用户中设置默认值时,它会清除存储的值,并且看起来您丢失了数据。在将它添加到默认值之前,我会检查一个 if 语句,即你的数组不是 nil,如果它是追踪它是如何没有命中你的 switch 语句的。

于 2013-10-03T18:09:23.610 回答