How can I show MBProgressHUD when perform segue to navigate between ViewControllers ?
You can try to show the HUD in the destination ViewController
put the HUD show code in:
(void)viewWillAppear:(BOOL)animated{
//MBProgressHUD code
}
This work for me.
Related
Im relatively new to iOS programming and have been making a recipe based app for the iPad. I've looked around at a lot of answers and can't seem to solve my problem so ill explain how my app is laid out.
Navigation controller -> ViewController -Modal segue -> PreviewViewController -modal segue -> Navigation Controller -> RecipeViewController
Within my RecipeViewController i have a button that when pressed i want it to go back to the "home" screen which for these purposes is the "ViewController".
Here is the code for the button action in "RecipeViewController":
- (IBAction)homeB:(id)sender {
ViewController* viewController = [[ViewController alloc]init];
[self.navigationController pushViewController:viewController animated:YES];
}
However, when i press this button the ViewController is displayed, but the screen is greyed out and i can have no interaction with the screen. I can't post an image of what the screen looks like as i don't have enough reputation yet but i will update it when i can.
I have tried other ways of displaying it such as connecting a segue in the storyboard between the button and the "ViewController" and then activating the segue when the button is pressed. But this messes up other parts of my code as i have to re allocate and initialise the home screen. Would appreciate any help as to why it is coming up with the greyed out screen that cannot be interacted with.
Also just some more notes:
self.navigationController
does not return nil so it is seen, and no errors are displayed when the button is pressed.
Thanks
If you're really doing segues, then I presume this was made in a storyboard. If that's the case, then you should use an unwind segue to get back to ViewController. You do this by adding an IBAction in ViewController that looks like this:
-(IBAction)comingBackFromRecipe:(UIStoryboardSegue*)sender {
NSLog(#"I'm back");
}
The important point is that the sender type be UIStoryboardSegue. Then in IB, in the RecipeViewController, you control drag from your button to the green "Exit" icon at the bottom of the controller. When you let go, you should see the method that you wrote in ViewController -- connect it to that. This will get you back to the same instance of ViewController that you started with.
It's hard to tell without seeing a screenshot, but from what i understand, if you want to go back to the home screen, you shouldn't be pushing a new view controller (unless you really want to add it to the stack?)
To go back to the "home" screen, you should try this:
[self.navigationController popToViewController:viewController animated:YES];
or if your home screen is the root, simply use this:
[self.navigationController popToRootViewControllerAnimated:YES];
Thanks for the responses everyone, i figured out my problem though. My structure was wrong and i realised that i didn't need to have another navigation controller for the Recipe view Controller as i wasn't pushing anywhere from there. So incase anyone else has a similar problem my structure is now as follows:
Navigation Controller -> View Controller -Modal Segue -> PreviewViewController - ModalSegue -> RecipeViewController
I removed the Navigation controller between PreviewViewController and RecipeViewController. This means that they are all modal view controllers. So to get back from the RecipeViewController to the home screen which is "ViewController" i just needed to dismiss the hierarchy of modal views with the following code:
UIViewController * parent = self.presentingViewController;
[parent.presentingViewController dismissViewControllerAnimated:YES completion:nil];
I went back two stages so that both the PreviewViewController and the RecipeViewController where dismissed.
Works great now, thanks for the help anyway everyone.
From my main view, i have a button that when pressed triggers a modal segue with curl effects, which in turn shows 3 buttons, which all have modal segues. When any of these buttons are pressed, they show another view, but i can't seem to get rid of the curled view. Any help is appreciated to get rid of the curled view before loading the new view.
Good day!
If it's modal, you can just call [self dismissModalViewControllerAnimated:YES]; in the view's class you want to dismiss.
since ios5 dismissModalViewControllerAnimated is deprecated, use this:
[self dismissViewControllerAnimated:TRUE completion:^{
//completion or NULL
}];
try this
[self.flipViewOneController.view removeFromSuperview];
I have a Navigation Controller with a View Controller displaying a button. The button is linked to another View Controller using a push segue which automatically adds a top navigation bar with a back button. This all works fine. Pressing the back button slides off the 2nd view and returns to the 1st.
I have a button on the 2nd View Controller, that when pressed runs some code and a delegate call back to the 1st View Controller. Again this works fine.
Now I just need to dismiss the 2nd pushed View from code as if the back button was pressed.
I have tried using dismissModalViewCcontrollerAnimated and dismissViewControllerAnimated, however they both dismiss the whole Navigation Controller which removes view 2 and 1 (returning bak to my main menu).
Whats the correct way to slide off the view.
Obtain a reference to your UINavigationController and call
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
on it.
In Swift it would be calling the method
navigationController?.popViewController(animated: true)
If we use push segue, then use popViewController
#IBAction func backButtonClicked(_ sender: Any) {
self.navigationController?.popViewController(animated: false)
}
In swift you can also call:
self.navigationController?.popToRootViewControllerAnimated(true)
On Objective-C is
[self.navigationController popViewControllerAnimated:YES];
for a jump to the first root controller
[self.navigationController popToRootViewControllerAnimated:YES];
or is a possible move to the specific controller
[self.navigationController popToViewController:(nonnull UIViewController *) animated:(BOOL)];
animation specific animation process of move the controller. If the animation is false the controller will appear without animations.
The UIViewController must be from one which is on the stack.
If NavViewController is used with UIModalPresentationFullScreen then the below line will work
self.navigationController?.dismiss(animated: true, completion: nil)
So, I am using a RootViewController from which you can display first ViewController Categories and then from Categories you display next ex. Music
RootViewController -> Categories -> Music
In RootViewController I use this
[self presentModalViewController:categoriesView animated:NO];
to present the modal view and then dismiss it from Categories with
[self dismissModalViewControllerAnimated:NO];
From Categories to Music I use again
[self presentModalViewController:fruitView animated:NO];
to present the Music modal view and then dismiss it in music with again the same as above.
Is there a possibility to dismiss two modal views? I want a method that leads from Music back to RootViewController, dismisses both last modal views.
Any ideas?
Hi Use this Following code[[[self presentingViewController] presentingViewController] dismissModalViewControllerAnimated:YES];
Are you sure you want to use modal views for this? It sounds like what you're trying to do is better solved with a UINavigationController, where you can push and pop view controller's in a stack (and there's a popToRootViewControllerAnimated: message you can use).
This is how drill-down navigation is idiomatically handled in iOS (in the iPod, Notes, Contacts, Videos, Photos apps for example).
There's sample code for this in Xcode, I believe.
UINavigationController has a popToRootViewControllerAnimated: method, which per the documentation:
Pops all the view controllers on the
stack except the root view controller
and updates the display.
Use popToRootViewControllerAnimated method of UINavigationController.
[self.navigationController popToRootViewControllerAnimated:YES];
What you're talking about here, going from more general to more specific views, is better handled with a UINavigationController pushing and popping views. These are the views which slide left and right on the screen. Pushing means it slides in from the right (and shows a new, more specific view). Popping slides back to the right and shows a more general view.
A modal view controller is the one that slides in from the bottom of the screen. Look at the iPod app on your device for the way to handle this.
I use a nice utility method to do this... see here:
How to dismiss the two or more dismissModalViewController?
Use This, In music view write this for dissmiss 2 view .
[RootViewController dismissModalViewControllerAnimated:YES];
Here RootViewController is an object of RootViewController
Hope this will help u.
I have a viewcontroller, and I would like to display a modal view controller with :
presentModalViewController when a user finished picking an image.
The modal view controller is working fine when I call it from a button in my main view.
But when I call it from didfinishpickingimage callback nothing happens.
Thanks.
Try
[picker dismissModalViewControllerAnimated:NO];
before
[self presentModalViewController:MY_VIEW_CONTROLLER animated:YES];
Note the animated variable
I had a similar issue. I decided to push the view controller I wanted to display after selecting an image onto my navigation controller instead of trying to present a modal view controller. It has the same effect as presenting a modal.
So I just did:
[self.navigationController pushViewController:MY_VIEW_CONTROLLER animated:YES];