selectTabViewItemAtIndex help

Discussion in 'Mac Programming' started by BollywooD, Apr 13, 2009.

  1. macrumors 6502

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #1
    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.
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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.
     
  3. macrumors 68020

    Krevnik

    Joined:
    Sep 8, 2003
    #3
    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.
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    That's what I first thought, but System Configuration does have a SCPreferences API, but it serves a different purpose.

    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.
     
  5. thread starter macrumors 6502

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #5
    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
     
  6. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    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.
     

Share This Page