Passing var value from the app delegate

Discussion in 'iOS Programming' started by spire.bt, Sep 14, 2010.

  1. spire.bt macrumors newbie

    Joined:
    Apr 8, 2010
    #1
    I have a simple question ( :confused: )


    if I have this code in the app delegate .m file

    Code:
    -(void){
    
            [UIView beginAnimations:nil context:NULL];
    	[UIView setAnimationDuration:1.0];
    		
    		[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:NO];
    		[settingsViewController.view removeFromSuperview];
    		
    		[self.window addSubview:[viewController view]];
    		
    		[UIView commitAnimations];
    		[settingsViewController release];
    		settingsViewController = nil;
    [B]int variableX=10;[/B]
    
    }
    
    
    how can I get this var so i can use it in the other view

    ex.
    In the AppViewControler.m

    Code:
    
    -(IBAction)UsedVar{
    
    Result = 2 + [B]variableX[/B];
    
    
    printf("%d and",Result);
    
    }
    
    
    lets say "-(IBAction)UsedVar" is connected to a button
     
  2. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #2
    You have to put your variable in the .h file of the app delegate (so it has class scope instead of just method scope) and make your variable a property.

    Then wherever with your variable you want to use it:

    Code:
    MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    
    delegate.myvar = 1;
    NSLog(@"%@",delegate.myvar);
    
     
  3. spire.bt thread starter macrumors newbie

    Joined:
    Apr 8, 2010

Share This Page