xcode changing view controllers issues

I have been developing an iPhone app and have come across a few issues. I do not have a storyboard in my app and have nothing in my xibs. I have initialised and set everything up through code. When I go to the GameViewController from my main viewcontroller everything is fine, however when I come back through my back button I get this issue:

Presenting view controllers on detached view controllers is discouraged .

When I re-arrive to the main view controller, there are little changes such as the view changing before its supposed to. Here is the code for the button on my

GameViewController *game = [[GameViewController alloc] initWithNibName:nil bundle:Nil];
    [self dismissViewControllerAnimated:YES completion:NULL];
    [self presentViewController:game animated:YES completion:NULL];

Here is the code for the back button:

ViewController *home = [[ViewController alloc] initWithNibName:nil bundle:nil];

[self dismissViewControllerAnimated:YES completion:NULL];
[self presentViewController:home animated:NO completion:NULL];

If anyone can help me to see what I am doing wrong that would be great.

Answers


You can not present home view controller from self because it is already dismissed. You should change

[self dismissViewControllerAnimated:YES completion:NULL];
[self presentViewController:home animated:NO completion:NULL];

to

UIViewController *parentViewController = self.presentingViewController;
[self dismissViewControllerAnimated:YES completion:^
 {
     [parentViewController presentViewController:home animated:NO completion:nil];
 }];

Need Your Help

How to automatically validate after typing the input without using any frameworks, just simple code for my registration form?

html css validation wamp

I want to know how to validate inputs after typing without using any frameworks or complicated code since this is only for my registration form?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.