Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

spire.bt

macrumors newbie
Original poster
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😕
 
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
}
 
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.
 
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.

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???
 
but what about the problem that i have???

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?
 
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;"

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?
 
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???

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.
 
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)
 
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)

Nobody is judging you, we are simply giving you some useful advice.
 
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)

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.


This is my way of learning, by making a real project (application)

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


Good luck
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.