相关疑难解决方法(0)

NSUserDefaults同步方法

 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@"xxxxxxxx" forKey:@"name"];

[defaults synchronize];
Run Code Online (Sandbox Code Playgroud)

我需要知道为什么我必须使用上面代码的最后一行[defaults synchronize]?使用它的目的是什么?这是必须的吗?

iphone cocoa-touch

49
推荐指数
4
解决办法
3万
查看次数

在NSuserdefaults中保存选定的cheklist行

我对Iphone很新,这是我项目中的最后一个模块.以下代码适用于chekmark的多个国家选择.基本上我的问题是如何保存这些选定的国家/地区,并在返回此视图时再次显示复选标记.请帮帮我..

我的didSelectRowAtIndexPath方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

  if([selectedCell accessoryType] == UITableViewCellAccessoryNone) 
  {
    [selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark];
    [selectedIndexes addObject:[NSNumber numberWithInt:indexPath.row]];
  }
  else
  {
    [selectedCell setAccessoryType:UITableViewCellAccessoryNone];
    [selectedIndexes removeObject:[NSNumber numberWithInt:indexPath.row]];
  }

  [tableView deselectRowAtIndexPath:indexPath animated:NO];
  [tableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)

我的cellForRowAtIndexPath方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath    *)indexPath 
{
    HolidayAppDelegate *delegatObj = (HolidayAppDelegate *)[UIApplication sharedApplication].delegate;

    static NSString *CellIdentifier = @"CustomCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    }

    cell.textLabel.text=[delegatObj.allcountryarray objectAtIndex:indexPath.row];

    [cell setAccessoryType:UITableViewCellAccessoryNone];

    for …
Run Code Online (Sandbox Code Playgroud)

nsuserdefaults ios

5
推荐指数
1
解决办法
814
查看次数

标签 统计

cocoa-touch ×1

ios ×1

iphone ×1

nsuserdefaults ×1