call void when showing the view

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

  1. spire.bt macrumors newbie

    Joined:
    Apr 8, 2010
    #1
    is there something that can call a -(void) every time a view shows.
    I am rotating between two views, so when i go to the second view and then return to the first view I want a void to be called automatically from the first view

    I've try to do this with
    Code:
     -(void)viewWillAppear:(BOOL)animated
    and
    Code:
     - (void)viewDidLoad
    by putting a NSLog in them but it doesn't print when i return to the first view. any suggestions?

    something like viewDidShow:confused:
     
  2. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #2
    How are you showing/hiding your second view? Post code.
     
  3. spire.bt thread starter macrumors newbie

    Joined:
    Apr 8, 2010
    #3
    I have two methods in the app delegate

    Code:
    -(void)goTo1{ 
    
     [self.window addSubview:[viewController view]]; 
     [settingsViewController.view removeFromSuperview];
    
    
     [UIView beginAnimations:nil context:NULL];
     [UIView setAnimationDuration:1.0];
      //removing the settingsViewController form the view and setting the animation
      [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:NO];
    
      [UIView commitAnimations];
      [settingsViewController release];
      settingsViewController = nil; }
    
    and

    Code:
    -(void)goTo2{
    
     //calling the .xib file and the SettingsViewController
     SettingsViewController *aSettingsView = [[SettingsViewController alloc] initWithNibName:@"Settings" bundle:nil];
     [self setSettingsViewController:aSettingsView];
     [aSettingsView release];
    
     [self.window addSubview:[settingsViewController view]];
     //moving the view 30px down
     [[settingsViewController view] setFrame:CGRectMake(0, 20, 320, 460)];
    
     [UIView beginAnimations:nil context:NULL];
     [UIView setAnimationDuration:1.0];
     //setting the animation
     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:YES];
    
     [UIView commitAnimations]; 
     [webskiAppBetaViewController release];
     webskiAppBetaViewController = nil;
    }
    
    and IBActions in the 2 view controllers
    first One

    Code:
    -(IBAction)goToView2{
    
     WebskiAppBetaAppDelegate *mainDelegate = (WebskiAppBetaAppDelegate *)[[UIApplication sharedApplication] delegate];
     [mainDelegate goTo2]; 
    }
    
    and teh second one

    Code:
    -(IBAction)goToView1{
     WebskiAppBetaAppDelegate *maniDelegate = (WebskiAppBetaAppDelegate *)[[UIApplication sharedApplication] delegate];
     [maniDelegate goTo1];
    }
    
    so now when i call goToVIew1 I also want to run a method that is in the view 1

    something like this

    Code:
    -(IBAction)goToView1{
    
     WebskiAppBetaAppDelegate *maniDelegate = (WebskiAppBetaAppDelegate *)[[UIApplication sharedApplication] delegate];
     [maniDelegate goTo1];
    [self methodInFirstVIew]; //this method exists in the first view
    }
    
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Also, your phrasing is a little strange: you don't "call a void"; you call a method whose return value happens to be void.
    Just like if you had:
    Code:
    - (NSString *)stringForThing;
    you wouldn't call an NSString* but rather you would call a method whose return type is NSString*.

    And if you want to be really technical: you don't even call methods; you pass a message to an object.

    EDIT:

    P.S. I don't think addSubview: triggers the viewWillAppear: or viewDidAppear: methods the way you'd like it to. You should probably consider presenting the views either modally or through a navigationController.
     
  5. spire.bt thread starter macrumors newbie

    Joined:
    Apr 8, 2010
    #5
    I don't see how this was helpful but "call a -(void) " obviously minds you so next time i will try to write "call the -(void) SomeVoid;"
    or from now on I will pass a message to an object, but what about the problem that i have???
     
  6. seepel macrumors 6502

    seepel

    Joined:
    Dec 22, 2009
    #6
    Well dejo answer that as well. You are essentially rewriting the modal view controller scheme when it seems like you don't have to. Is there a reason you are not using a modal view controller?
     
  7. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #7
    Learning to refer to language constructs in the same way as everyone else is generally useful as it helps avoid confusion. ;)

    Have you considered using the UIView animation callbacks (animationDidStopSelector: off of the top of my head - check the docs) to perform a selector when the flip animation has finished?
     
  8. Sykte macrumors regular

    Joined:
    Aug 26, 2010
    #8
    Personally I would step back and pick up a book and do some reading before moving forward. You're missing a huge foundation that will hurt you later on when trying to get an app approved. Programming is very similar to any other langauge, hence 'programming langauge'. Sure you may know a few words in french but that doesn't mean you can form a proper sentence.
     
  9. spire.bt thread starter macrumors newbie

    Joined:
    Apr 8, 2010
    #9
    Thx for the responses but don't you judge me for my coding I'm learning. I'm sure none of you just started knowing Objective C from nowhere.
    This is my way of learning, by making a real project (application)
     
  10. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #10
    Nobody is judging you, we are simply giving you some useful advice.
     
  11. Sykte macrumors regular

    Joined:
    Aug 26, 2010
    #11
    Not trying to judge only trying to help you understand that a solid foundation is extermely important and overall your learning process will be shorter and easier.


    Which isn't wrong just don't forget to read ->(edit:learn) the fundamentals.


    Good luck
     

Share This Page