Сохранить отмеченную галочкой строку в appsettings.РЕДАКТИРОВАНИЕ - PullRequest
0 голосов
/ 18 апреля 2011

РЕДАКТИРОВАТЬ: я получил экономию, и теперь она не работает.

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:countries  forKey:@"country"];
[defaults synchronize]; 

Сохранение.

Но я думаю, что должен загрузить массивы из настроек приложения. как?

Получил это сейчас:

countries = [[NSArray alloc] initWithObjects:@"All",@"Austria",@"Belarus",@"Canada",@"Czech Republic",@"Denmark",@"Germany",@"Finland",@"France",@"Latvia",@"Norway",@"Russia",@"Slovakia",@"Slovenia",@"Switzerland",@"Sweden", @"USA", nil];

1 Ответ

0 голосов
/ 18 апреля 2011

Использовать синхронизировать метод NSUserDefault .

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        int newRow = [indexPath row];
        int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;

        if (newRow != oldRow)
        {
            UITableViewCell *newCell = [tableView cellForRowAtIndexPath:
                                        indexPath];
            newCell.accessoryType = UITableViewCellAccessoryCheckmark;

            UITableViewCell *oldCell = [tableView cellForRowAtIndexPath: 
                                        lastIndexPath]; 
            oldCell.accessoryType = UITableViewCellAccessoryNone;
            lastIndexPath = indexPath;
        }
        NSUInteger row = [indexPath row];
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        //Suppose you have used **myArrayUsedInTableView**   Array to construct TableView 
        ..................................................................................
        ............./*Do changes here in myArrayUsedInTableView  as per your requirement*/
        ....................................................................................
        //Now store your array myArrayUsedInTableView in NSUserDefault
        [defaults setObject:myArrayUsedInTableView  forKey:@"StoredArray"];
        [defaults synchronize]; 
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...