After segue ViewDidLoad is called but ViewWillAppear and ViewDidAppear is not being called - xcode4.3

I have created a segue in storyboard named "CreateGame".And called it with my viewController to Load CreateGameViewController using[self performSegueWithIdentifier:#"CreateGame" sender:nil] but is is not working. it was working some time ago but suddenly it is not working.
I have taken a look of my code. My
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(#"Segue");
}
is being executed each time when i call [self performSegueWithIdentifier:#"CreateGame" sender:nil]and then CreateGameViewController's"viewDidLoad" is being executed (conformed by using NSLog(); statement) . but CreateGameViewController's ViewWillApper is not being called.
i am using NavigationController So type of segue is 'Push'. some times segue works or sometimes not. Please help me out.

you are doing something in your CreateGameViewController's "viewDidLoad" (may be some looping or some recursion function calling without end) . That would have prevent the screen appears. it would be more helpful if you can provide the code of CreateGameViewController's "viewDidLoad"

Related

UITableView ignoring method call only on iPhone 5

This seems strange, and maybe I don't have the issue fully nailed, but I am perplexed.
In my app, I present a UITableView modally in a VC and have created a custom init method to additionally send an index path for where the table should scroll to.
in ViewDidLoad, the following call is executed correctly on iPhone4S and earlier, but ignored on iPhone5:
[table scrollToRowAtIndexPath:iP atScrollPosition:UITableViewScrollPositionTop animated:NO];
Any suggestions? Have I made any false assumptions?

Getting viewDidLoad to be called when using popViewControllerAnimated

I'm using a UINavigationController to navigate between classes. When I press a button on the first view to send me to the second one, everythin works fine. But when I wan't to return from the second, to the first view, the viewDidLoad method isn't being called, and I really need that to happen.
According to this post, I should somehow set my view to nil but I'm not sure where or how to do that. This is the code that I'm using to return to the first view:
NewSongController *nsContr = [[NewSongController alloc] initWithNibName:#"mNSController" bundle:nil];
[self.navigationController popViewControllerAnimated:YES];
[nsContr release];
Your code is not correct.
You don't need to instantiate your first controller in order to pop to it. It already exists.
viewDidLoad will only run when you load the viewController for the first time (i.e. when you push to it). When you push to other controllers they are put onto a stack (imagine a stack of cards). When you push another card onto the stack the cards beneath it are already there.
When you pop it is like removing a card from the stack. But the card underneath is already there so it doesn't need to load again. All it does is run viewWillAppear.
All you need to do to pop back is...
[self.navigationController popViewControllerAnimated:YES];
That's it.
Remove the stuff about NewSongController (if that is what you are trying to go back to).
Then in the NewSongController function - (void)viewWillAppear:animated; put the code you want to run when you get back to it.
Hope that helps.
Your first view is loaded and is pushed onto the navigation stack. Dont try to mess with whats on the stack without fully understanding how setting the view to nil will affect the behavior.
Whatever you do on viewDidLoad, doing it in viewWillAppear or viewDidAppear will give you the result you want.
The viewDidLoad wouldn't appear because it already exists in the navigation stack. Since you are going back in the stack you would want to have the code that you want to trigger in viewWillAppear or viewDidAppear which is executed when popping from one viewcontroller to the one below it.

Weird segue animation in xcode

Ok guys this is killing me. I have 10 "view controllers" in a row across my storyboard. All ten use the same .h and .m file. Each has a segue connecting it to the next one in line. All of the segues have the following identifier: segueToNextPage. I'm calling the segue with this method:
-(void)myMethod {
// other code
[NSTimer scheduledTimerWithTimeInterval:4 target:(self) selector:#selector(nextPage) userInfo:(nil) repeats:NO];
}
-(void)nextPage {
[self performSegueWithIdentifier: #"segueToNextPage" sender: self];
}
On the storyboard I have set the segue's transition to cross dissolve. I have also set the transition style of all "view controllers" on the storyboard to cross dissolve.
The segue works fine when called except it does this corner to corner spin/flip animation not the cross dissolve as i had expected.
I made a test project with just two pages just to be sure that I wasn't losing my mind and everything works as expected if I use this code and connect it to a round rect button:
-(IBAction)nextPage {
[self performSegueWithIdentifier: #"segueToNextPage" sender: self];
}
Can anyone spare the time to explain why my first example doesn't work as expected. It would be greatly appreciated.
I replicated your code and it seemed to work without a problem. The only issue that I can think of is that by defining the "segueToNextPage" segue multiple times in the StoryBoard you are potentially overwriting its definition each time. You should check each one of the transitions and make sure that one of them is not set to "Flip Horizontal"
Im still not sure whats causing this to happen with those ten "view controllers" on the storyboard but making a new .h and .m with the exact same code in it then hooking those to ten new view controllers on the storyboard has fixed the issue. I was even able to copy and paste the contents of the original view controllers into the new ones. Still very strange but for now problem solved.

Why doesn't performSegueWithIdentifier work inside viewDidLoad?

I'm trying to trigger a storyboard segue as soon as viewDidLoad is called on a view controller. The segue has an identifier attached, and works fine when called from inside a method thats linked to a button or other control. But it doesn't work inside of viewDidLoad. It just silently fails. Is there some rule about segue's being ignored in viewDidLoad?
I've tried both this:
[self performSegueWithIdentifier: #"mySegue"
sender: self];
and this:
[self dismissViewControllerAnimated:YES completion:^() {
[self performSegueWithIdentifier:#"mySegue" sender:self];
}];
Neither work.
You can not dismiss a view controller that isn't presented yet. didLoad has purely memory management functions, you can use it as (part of a) constructor.
What may work, is to start a segue in viewDidAppear, however I would suggest to start with the view you want at the first time.
Most likely reason could be that the OS ignores second screen transition call while one is in progress. In your ViewDidLoad, the view transition (of the current view) is still not complete. You are asking another transition before it completes and the OS ignores it. It must be the reason that the segue works when called from a different function. Try calling inside ViewDidAppear (or after a time delay)

Objective C Beginner: where to put code that needs to be executed once in UITableViewController

I have UITableViewController where I need to put initialization code only once to populate data source. in which method to put this code.
I tried with viewWillAppear: method, but it get executed every time view appear.
if you want to display things only once that the View has comed on screen, then yeah. go for it. Otherwise you also have ViewdidLoad or ViewWillAppear if you have to arrange things before the view begins the transition to slide in.
All of these methods will be executed every time from the tableView you tap on a row.
anyway the pattern you are trying to achieve is called singleton, you can find out about it more over here
What should my Objective-C singleton look like?
You can put it in viewDidLoad and it will be only once.
The - (void)viewDidLoad method is probably the place you want use. It gets called once the view controller has finished doing its loading code (either by loading a XIB or by calling loadView).