how to close the view controller that I open with "replace" segue - ios

I've unsuccessfully tried:
1. [self dismissViewControllerAnimated:YES completion:Nil];
2. [[self parentViewController] dismissViewControllerAnimated:YES
completion:Nil];
3. //from the parent view controller using a delegate
-(void)closeReplaceController
{
DLog(#"closeReplaceController");
[self dismissViewControllerAnimated:YES completion:Nil];
}

I would try something like this:
-(void)killPresentingView
{
UIViewController *vc = [self presentingViewController];
[vc dismissViewControllerAnimated:YES completion:nil];
}
And see what happens. If I understood you right, this should work.

Related

Dismiss self present view from itself

I have a web view controller, suppose A
The weviewcontrollerA contain 2 button at top ButtonA and ButtonB
Now my question is
From Another ViewControllerX i load weviewcontrollerA by passing URL as parameter, to load www.google.com in the webviewControllerA view.
for example :
-(IBAction)loadweviewcontrollerA
{
weviewcontrollerA *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"weviewcontrollerA"];
vc.urltoload=#"https://wwww.google.com";
[self presentViewController:vc animated:NO completion:nil];
}
Now in webviewcontrollerA , i have to reload the same view again with below condition
1) Reloading the viewDidload (or present the same class again) is compulsory as i have to pass some Parameter in the uRL also as HTTPRequest with the weburl
2) how to dismiss webviewcontrollerA , and then suddenly load it again without user known it.
how i jump,below code work, but user see ViewControllerX and the it load again, how i skip that user not visible the ViewControllerX or it load so quickly without user notice
-(IBAction)ButtonA
{
[self dismissViewControllerAnimated:NO
completion:^{
weviewcontrollerA *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"weviewcontrollerA"];
vc.urltoload=#"https://wwww.facebook.com";
UIViewController *topvc=[self topMostController];
[topvc presentViewController:vc animated:NO completion:nil];
//[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:vc animated:YES completion:nil];
}];
-(IBAction)ButtonG
{
[self dismissViewControllerAnimated:NO
completion:^{
weviewcontrollerA *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"weviewcontrollerA"];
vc.urltoload=#"https://wwww.twitter.com";
UIViewController *topvc=[self topMostController];
[topvc presentViewController:vc animated:NO completion:nil];
//[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:vc animated:YES completion:nil];
}];
//----------- END OF MORE INFO POP UP VIEW---------------
- (UIViewController*) topMostController
{
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
return topController;
}

Display RootViewController only when dismiss current ViewController

I'm doing an ios project without using any story board and xibs.
Here I've come out one problem on presenting my UIViewController.
Here is the senario:
My RootViewController has 2 UIButton's that can present ViewControllerA and ViewControllerB when being pressed.
-(IBAction)btnAclicked:(id)sender{
[self.navigationController presentViewController:ViewControllerA];
}
-(IBAction)btnBclicked:(id)sender{
[self.navigationController presentViewController:ViewControllerB];
}
And now inside ViewControllerA
I have a button to presentViewContollerB as well, and I want only the RootViewController to be displayed when I dismiss ViewContollerB.
In order to do this, I need to dismiss ViewControllerA first then presentViewControllerB. I know there is ways like using delegate to make it works, but I just want to know if there is any easier way to do this.
To be emphasised is that I want to use presentViewController only, not pushViewController. Thanks
I have an answer for your question,just do the following code,
in RootViewController.m
- (IBAction)gotoViewA:(id)sender
{
ViewControllerA *viewControllerA = [[ViewControllerA alloc]initWithNibName:#"ViewControllerA" bundle:nil];
[self presentViewController:viewControllerA animated:YES completion:nil];
}
- (IBAction)gotoViewB:(id)sender
{
ViewControllerB *viewControllerB = [[ViewControllerB alloc]initWithNibName:#"ViewControllerB" bundle:nil];
[self presentViewController:viewControllerB animated:YES completion:nil];
}
in ViewControllerA.m
- (IBAction)actionBackFromA:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
in ViewControllerB.m
- (IBAction)actionBackFromB:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Use the completion block of presentviewcontroller,viz will executed first
[self presentViewController:goTo_B animated:YES completion:^{
//Dismiss A
[self dismissViewControllerAnimated:YES completion:nil];
}];
If this does not work,write dismiss and just after it present your new controller
[self dismissViewControllerAnimated:YES completion:nil];
[self.view.window.rootViewController presentViewController:goTo_B animated:YES completion:^{ }];
There's another way out, but i don't know whether its appropriate or not.
Create a property of type View Controller A in view controller B.
While presenting view controller B, assign an instance of View Controller A to the property in view Controller B.
[self presentViewController:goTo_B animated:YES completion:^{
goTo_B.propertyOfViewControllerA = self;
}];
After that while dismissing view controller B you can do the either of the two:
[self dismissViewControllerAnimated:YES completion:nil];
[propertyOfViewControllerA dismissViewControllerAnimated:YES completion:nil]
or
[self dismissViewControllerAnimated:YES completion:^{
[propertyOfViewControllerA dismissViewControllerAnimated:YES completion:nil]
}];

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.
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];
}];

Instance method '-presentViewController:animated' not found

I'm fairly new to this, so bear with me. I have 2 errors left to fix in my code. In both cases my instance methods are not found:
-(IBAction)goFlipSide {
NSLog(#"goFlipSide has been called:");
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES];
[controller release];
}
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
[self dismissViewControllerAnimated:YES];
//This method gets fired when the user clicks done on the modal FlipsideViewController. This is different
//than the viewWillAppear.
self.navigationController.navigationBarHidden = TRUE;
/*
if (self.goViewSuccess == TRUE) {
//if the goViewSuccess boolean is set to YES - then we can load the load the goViewController
NSLog(#"goViewSuccess is YES");
[self loadGoViewController];
}
*/
}
Both instance methods not found are: presentViewController: and dismissViewControllerAnimated:.
What class is self? Those methods are only found on UIViewController. The full selectors are:
presentViewController:animated:completion:
dismissViewControllerAnimated:completion:
Try adding the completion block argument.
The code is supposed to be this
[self dismissViewControllerAnimated:YES completion:nil];
or if you want something when its done,
[self dismissViewControllerAnimated:YES completion:^{
//do stuff
}];
And for the other one
[self presentViewController:controller animated:YES completion:nil];

presentViewController doesnt "see" my viewControllers

MainMenuViewController presents BonusViewController modally. I want to Dismiss BonusViewController then display a new BonusViewController, effectively "resetting" BonusViewController.
Im using notifications to call this method in MainMenuViewController
-(void)resetBonus{
[self dismissViewControllerAnimated:YES completion:nil];
[self presentViewController: BonusViewController animated:NO completion:nil];
}
I expected BonusViewController to be auto-detected as I was typing it in the presentViewController call above but it was not and none of my viewControllers show up as I type which Im assuming means im doing this all wrong. Do I have to initialize the VC or allocate it before I can present it like this? Or can I even do this at all since im using storyboards?
I also tried this though I believe this method is deprecated
-(void)resetBonus{
[self dismissModalViewControllerAnimated:YES];
[self presentModalViewController: BonusViewController animated:NO ];
}
Did what Sumanth suggested but I get this message now:
so now I m doing :
#import "BonusViewController.h
....
-(void)resetBonus
{
BonusViewController *bonus = [[BonusViewController alloc]init];
[self dismissModalViewControllerAnimated:NO];
[self presentModalViewController: bonus animated:NO ];
}
the errors are all gone but when BonusViewController is presented the display is solid black, i can hear the sounds going but cant see anything on the screen
you should allocate and initialize the viewcontroller and present that using presentModalViewController write like this
BonusViewController *bonus = [[BonusViewController alloc]init];
[self dismissModalViewControllerAnimated:YES];
[self presentModalViewController: bonus animated:NO ];
Also dont forget to write #import "BonusViewController.h" in .h file
BonusViewController *objBonus = [[BonusViewController alloc]init];
[self dismissViewControllerAnimated:YES completion:NULL];
[self presentViewController:objBonus animated:YES completion:NULL];
You need to create and object of the viewcontroller and you are directly passing the viewcontroller which is not possible
#import "BonusViewController.h"
-(void)resetBonus
{
BonusViewController *BonusViewController = [[BonusViewController alloc]init];
[self dismissViewControllerAnimated:NO completion:nil];
[self presentViewController: BonusViewController animated:NO completion:nil];
}
Set Both of animated is NO
EDIT : #import "BonusViewController.h"
Im sure the answers given were correct but I could not get them to work properly. For some reason BonusViewController seems to be displayed as I can hear the sounds going but the screen is black and nothing is displayed visually.
I ended up doing the below for now in the intrest of time but this isnt the smooth effect I was really going for.
I have to re-visit this when I have more time to figure out a better way to do it.
-(void)endBonus
{
[self dismissViewControllerAnimated:NO completion:^{
[self performSelector:#selector(resetBonus) withObject:nil afterDelay:1];
}];
}
-(void)resetBonus
{
[self performSegueWithIdentifier: #"segueToBonus" sender: self];
}

Resources