Global Variables? or accessing one variable in one function in another function?

Discussion in 'iOS Programming' started by MythicFrost, Dec 19, 2009.

  1. MythicFrost macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #1
    Alright basically I have a very simple task:
    Show my Default.png image on my UIImageView, add it to my current view, run a function after 3 seconds that removes the UIImageView from my current view and releases it.

    I have several issues though, the first being more important, I can't access ivSplash in the dismissSplashScreen function, since it's declared (as a local variable) in the viewDidLoad function.
    Normally, I'd just declare the variable outside of the function but I've tried this in objective c but that doesn't really work properly (at least the way I do it).

    This is the code:
    Code:
    - (void)viewDidLoad {
    	[super viewDidLoad];
    	UIImageView *ivSplash = [[UIImageView alloc] initWithImage:([UIImage imageNamed:(@"Default.png")])];
    	[[self view] addSubview:(ivSplash)];
    	[self performSelector:@selector(dismissSplashScreen) withObject:nil afterDelay:3.0];
    }
    //Functions
    - (void)dismissSplashScreen {
    	//I want to remove the UIImageView from my view
    	//Then I will release it from memory? [ivSplash release];
    }
    Basically I want to get rid of the splash screen because I do not need it anymore. Any idea's? Thanks.
     
  2. jrdoner macrumors newbie

    Joined:
    Nov 26, 2009
    Location:
    Florida
    #2
    I'm still in XCode 101 myself, but instead of declaring your splash view as local to a function, declare it as a local variable for the object, and then clean it up with a timer.
     
  3. MythicFrost thread starter macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #3
    I'm not sure what that means
    Wouldn't I encounter the same problem not being able to access it?

    Thanks for your reply.

    EDIT: lol I just declared UIImageView *ivSplash; in my header file and now it works in .m just how I want, that's fantastic!
     

Share This Page