Need help with NSUserDefaults and UITabBarController

Discussion in 'iOS Programming' started by guydor, Apr 17, 2010.

  1. guydor macrumors member

    Joined:
    Mar 10, 2009
    #1
    Hi,

    I want to save the order of UITabBarController's tabs.
    I used this code and got 2 warnings.
    What should I do?

    Code:
    
    - (void)applicationDidFinishLaunching:(UIApplication *)application {     
    
    	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    	NSInteger tabsOrder = [defaults integerForKey:kCustomizedTabs];
    	self.rootController.customizableViewControllers = tabsOrder;
    	
    }
    
    
    - (void)applicationWillTerminate:(UIApplication *)application {
    	
    	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    	NSInteger tabsOrder = self.rootController.customizableViewControllers;
    	[defaults setInteger:tabsOrder forKey:kCustomizedTabs];
    	
    }
    
    
    Edit:
    Here are the warnings:
    Code:
    passing argument 1 of 'setCustomizableViewControllers:' makes pointer from integer without a cast
    self.rootController.customizableViewControllers = tabsOrder;
    
    
    initialization makes integer from pointer without a cast
    NSInteger tabsOrder = self.rootController.customizableViewControllers;
    
    
    Thanks!
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    What are the warnings? On what lines? Without that information I've no idea what you expect us to help you with!

    Edit to add: OK, it's obvious: you are using NSInteger as an object when it's not. Use NSNumber to wrap it.
     
  3. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #3
    What's the warning?


    Do you ever initialize a kCustomizedTabs variable?

    Code:
    NSInteger tabsOrder = [defaults integerForKey:kCustomizedTabs];
     
    Does this actually return an integer?

    Code:
    self.rootController.customizableViewControllers
     

Share This Page