Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BollywooD

macrumors 6502
Original poster
Apr 27, 2005
372
46
Hamburg
I am trying to remember window state in my app, and reload on launch. I save the tabViewItemAtIndex to defaults, and this works well. I cant seem however to read that integer back, and restore my tab?

Here is the function:

Code:
- (void) awakeFromNib
{
	int tabState;
	tabState = [[SCPreferences userDefaults]  integerForKey:SCPreferencesTabStateKey];
	if (tabState == 0)
	{
		[tabView selectTabViewItemAtIndex:0];
	}
	if (tabState == 1)
	{
		[tabView selectTabViewItemAtIndex:1];
	}
	if (tabState == 2)
	{
		[tabView selectTabViewItemAtIndex:2];
	}
}

does anyone have any ideas?

I also would like to remember window size, somehow.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Unless you have very good reason for using the SCPreferences APIs, don't. Use NSUserDefaults. Plus, isn't this code giving you an error? I don't see any class named SCPreferences.

Also your code could be reduced to this and avoid the if-else:
Code:
[tabView selectTabViewItemAtIndex:tabState];

To save a window's position and size, give it an Autosave name in IB.
 

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
Unless you have very good reason for using the SCPreferences APIs, don't. Use NSUserDefaults. Plus, isn't this code giving you an error? I don't see any class named SCPreferences.

Looks like he is using 'SC' as a prefix on his own code. This is actually a bad idea as the System Configuration APIs use 'SC' as their prefix. It will lead to confusion.

The one thing I'm confused about is why he would need his own object/class to expose the userDefaults. Subclassing NSUserDefaults usually doesn't provide much benefit either.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Looks like he is using 'SC' as a prefix on his own code. This is actually a bad idea as the System Configuration APIs use 'SC' as their prefix. It will lead to confusion.

That's what I first thought, but System Configuration does have a SCPreferences API, but it serves a different purpose.

The one thing I'm confused about is why he would need his own object/class to expose the userDefaults. Subclassing NSUserDefaults usually doesn't provide much benefit either.

Yes, normally this wouldn't be needed, but if you're writing a plugin you might want to write a wrapper class since NSUserDefaults will use the main app's identifier instead of yours.
 

BollywooD

macrumors 6502
Original poster
Apr 27, 2005
372
46
Hamburg
I am using SC as a prefix, for all my classes....
I didnt realise, it would cause confusions?

I am writing a plugin:
Safari Cookies

I think that the rembering tab state, mught be just bloat, and a little excessive, so Ill leave it out.


thanks for your help
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
It's not bloat, it's just most likely a bug in your class since the code looks fine. You could also double-check and make sure your tab view is valid at this point too.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.