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];
}
Related
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]
}];
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];
}];
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.
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];
I am using the facebook FBFriendPickerViewController and want the user to only be able to select one friend and then have it dismiss the view controller. In the FBFriendPickerDelegate, under the selectionDidChange method I am trying to capture what friend they selected and then dismiss the view controller. I can't get it to dismiss, I feel like I have done this type of thing many times before so I feel kind of dumb asking this, but I feel like I have exhausted every variation of this and nothing works.
-(void)friendPickerViewControllerSelectionDidChange:(FBFriendPickerViewController *)friendPicker{
self.selectedFriends = friendPicker.selection;
NSLog(#"%#", self.selectedFriends);
[friendPicker dismissViewControllerAnimated:YES completion:nil];
}
I have also tried
[[friendPicker parentViewController] dismissViewControllerAnimated:YES completion:nil];
[self.friendPickerController dismissViewControllerAnimated:YES completion:nil];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
[[friendPicker navigationController] dismissViewControllerAnimated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
all to no avail.
Since it's a navigation Viewcontroller that you likely pushed, you would want to pop it:
[self.navigationController popViewControllerAnimated:YES];
If you present the friendpicker controller modally you can dismiss it by using the facebookViewControllerCancelWasPressed and the facebookViewControllerDoneWasPressed methods of the FBViewControllerDelegate protocol. If you conform to FBFriendPickerDelegate you automatically conform to the first one.