<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Saving NSUserDefaults under iOS 4</title>
	<atom:link href="http://www.neilinglis.com/2010/07/17/saving-nsuserdefaults-under-ios-4/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.neilinglis.com/2010/07/17/saving-nsuserdefaults-under-ios-4/</link>
	<description>iPhone, iPad, Mac and Java Development Tales With a Sprinkling of Life Lessons</description>
	<lastBuildDate>Wed, 18 Jan 2012 11:06:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: itsfall</title>
		<link>http://www.neilinglis.com/2010/07/17/saving-nsuserdefaults-under-ios-4/comment-page-1/#comment-126</link>
		<dc:creator>itsfall</dc:creator>
		<pubDate>Mon, 24 Jan 2011 18:08:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.neilinglis.com/?p=11#comment-126</guid>
		<description>its still not working :(
everytime i close the app in multitasking and open it again its not saved..

here is my code:
table.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    static NSString *CellIdentifier = @&quot;Cell&quot;;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
	NSDictionary *dict = [array objectAtIndex:indexPath.section];
	NSArray *ns = [dict objectForKey:@&quot;Services&quot;];
	NSString *text = [ns objectAtIndex:indexPath.row];
	cell.textLabel.text = text;

	NSUserDefaults *stringDefault = [NSUserDefaults standardUserDefaults];
	NSString *defaultSetting = [stringDefault stringForKey:@&quot;shortSetting&quot;];

	if (cell.textLabel.text == defaultSetting) {
		cell.accessoryType = UITableViewCellAccessoryCheckmark;
	}

	return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{    
	UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];	
	NSUserDefaults *stringDefault = [NSUserDefaults standardUserDefaults];
	[stringDefault setObject:cell.textLabel.text forKey:@&quot;shortSetting&quot;];
	[stringDefault synchronize];
	[tableView deselectRowAtIndexPath:indexPath animated:YES]; 
	if (indexPath.section == 0) 
	{
		if (cell.accessoryType == UITableViewCellAccessoryNone) 
		{
			[self dismissModalViewControllerAnimated:YES];
			cell.accessoryType = UITableViewCellAccessoryCheckmark;
			[tableView deselectRowAtIndexPath:indexPath animated:YES]; 
		}
	}
}

and in my appdelegate: 

- (void)applicationDidEnterBackground:(UIApplication *)application {
	NSUserDefaults *stringDefault = [NSUserDefaults standardUserDefaults];
	[stringDefault synchronize];
}
- (void)applicationWillTerminate:(UIApplication *)application {
	NSUserDefaults *stringDefault = [NSUserDefaults standardUserDefaults];
	[stringDefault synchronize];
}

would be great if you can help me!
greetz
itsfall</description>
		<content:encoded><![CDATA[<p>its still not working <img src='http://www.neilinglis.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
everytime i close the app in multitasking and open it again its not saved..</p>
<p>here is my code:<br />
table.m<br />
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath<br />
{<br />
    static NSString *CellIdentifier = @&#8221;Cell&#8221;;<br />
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];<br />
    if (cell == nil) {<br />
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];<br />
    }<br />
	NSDictionary *dict = [array objectAtIndex:indexPath.section];<br />
	NSArray *ns = [dict objectForKey:@"Services"];<br />
	NSString *text = [ns objectAtIndex:indexPath.row];<br />
	cell.textLabel.text = text;</p>
<p>	NSUserDefaults *stringDefault = [NSUserDefaults standardUserDefaults];<br />
	NSString *defaultSetting = [stringDefault stringForKey:@"shortSetting"];</p>
<p>	if (cell.textLabel.text == defaultSetting) {<br />
		cell.accessoryType = UITableViewCellAccessoryCheckmark;<br />
	}</p>
<p>	return cell;<br />
}<br />
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath<br />
{<br />
	UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];<br />
	NSUserDefaults *stringDefault = [NSUserDefaults standardUserDefaults];<br />
	[stringDefault setObject:cell.textLabel.text forKey:@"shortSetting"];<br />
	[stringDefault synchronize];<br />
	[tableView deselectRowAtIndexPath:indexPath animated:YES];<br />
	if (indexPath.section == 0)<br />
	{<br />
		if (cell.accessoryType == UITableViewCellAccessoryNone)<br />
		{<br />
			[self dismissModalViewControllerAnimated:YES];<br />
			cell.accessoryType = UITableViewCellAccessoryCheckmark;<br />
			[tableView deselectRowAtIndexPath:indexPath animated:YES];<br />
		}<br />
	}<br />
}</p>
<p>and in my appdelegate: </p>
<p>- (void)applicationDidEnterBackground:(UIApplication *)application {<br />
	NSUserDefaults *stringDefault = [NSUserDefaults standardUserDefaults];<br />
	[stringDefault synchronize];<br />
}<br />
- (void)applicationWillTerminate:(UIApplication *)application {<br />
	NSUserDefaults *stringDefault = [NSUserDefaults standardUserDefaults];<br />
	[stringDefault synchronize];<br />
}</p>
<p>would be great if you can help me!<br />
greetz<br />
itsfall</p>
]]></content:encoded>
	</item>
</channel>
</rss>

