I have a strange problem in my app. When I'm pressed backButton from UINavigationController I trying to handle it with -(void) viewWillDisappear:(BOOL)animated in a next way:
-(void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated] ;
[self dismissViewControllerAnimated:YES completion:^{
[self.navigationController popToRootViewControllerAnimated:YES];
}];
}
After it I want do some code in -(void)viewDidAppear:(BOOL)animated of my rootTableViewController. But it's seems like that method wasn't called, but my controller
is changed to root(visual at least ). Have you any idea what I do wrong & how to resolve it?
Related
I created a library, and if the main app call my library its showing it, and download some data from server. But if the server has some error I would like to kill the library view, but it's not working
I have a delegate in the host app:
-(void)libraryResult:(NSString*)result{
NSLog(#"result: %#", result);
}
And I download data from server in the viewWillAppear method, and the download has a delegate method like this:
-(void)networkManagerError:(NSString *)error{
[hud hide:YES];
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
[self.delegate libraryResult:error];
}
I see in the log, that the app return to the main app, but the view don't change.
How to solve this? Whats wrong with my code?
Change this line
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
To
[self dismissViewControllerAnimated:YES completion:nil];
try these..
[self dismissViewControllerAnimated:YES completion:nil];
If you have VC1 which presents VC2, then inside VC2 at the corresponding event (say a Close button tap, or error from server etc.), you should call:
[self.presentingViewController dismissViewControllerAnimated:YES completion:^{
}]
If you set up things in such a way that VC1 is notified about those events that happen inside VC2, you can use:
[self dismissViewControllerAnimated:YES completion:nil];
However, the 1st method is more preferred, as it's a better design practice, and contributes to more loose coupling between VC1 and VC2.
Try to fire a notification from your "library result" method if error occurred and add an observer to your current controller view.
[[NSNotificationCenter defaultCenter] postNotificationName:Remove_CurrentView object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(remove) name:Remove_CurrentView object:nil];
-(void)remove{
[self dismissViewControllerAnimated:YES completion:nil];
}
I am new to iOS Programming and now i have a problem.
There is a login screen that use [self presentViewController:loginview animated:YES completion:nil]; to show it out in MasterViewController.
And now i want to call a method (reload data) after [self dismissViewControllerAnimated:YES completion:nil]
this is my code:
[self dismissViewControllerAnimated:YES completion:^ {
[self getPostData]; // Reload Data
[self.tableView reloadData]; // Reload Data
}];
but it is not working.
(the reload method is in the MasterViewController)
Anyone can help me?
You can use NSNotificationCenter for your problem.
Define a NSNotification in your MasterViewController viewDidLoad like below
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(closeModal:) name:#"CloseModal" object:nil];
And then define the method as below
-(void)closeModal:(NSNotification *)notification{
UIViewController *controller=(UIViewController *)notification.object;
[controller dismissViewControllerAnimated:YES completion:^ {
[self getPostData]; // Reload Data
[self.tableView reloadData]; // Reload Data
}];
}
And at last from your other controller from where you are actually trying to dismiss your controller use code below
[[NSNotificationCenter defaultCenter] postNotificationName:#"CloseModal" object:self];
what you should do is basically call method on presenting view controller as below
[(MasterViewController*)self.presentingViewController reloadData];
You can call the presentingViewController's methods which updates the Presenting view.
for example: I have a modal view which can be launched from multiple Views. And all the presenting views have the view reloading code within view will appear.
Add the below code before dissmissing the modal view.
[self.presentingViewController viewWillAppear:YES];
[self dismissViewControllerAnimated:YES completion:Nil];
I am trying to create an app that has a navigation bar at the bottom of the first view controller. When the user presses next they are taken to the second view controller in the storyboard. I would like to know if it is possible to make the program automatically take the user back to the first view controller after 10 seconds? I am very new to xcode so any help implementing this in a simple fashion would be greatly appreciated
just create a function and call that after time delay and push in that
in second viecontroller
- (void)viewDidLoad
{
[super viewDidLoad];
[self performSelector:#selector(yourMethod) withObject:nil afterDelay:10.0];
}
-(void)yourMethod
{
//[self.navigationController popViewControllerAnimated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}
hope this will help you
Add the below to viewDidLoad in your second view controller
- (void)viewDidLoad {
[super viewDidLoad];
[self performSelector:#selector(viewWillDisappear:) withObject:nil afterDelay:2.0];
//I have given 2 seconds. you can change as your wish
}
Add this method too below.
-(void) viewWillDisappear:(BOOL)animated{
[self dismissViewControllerAnimated:YES completion:nil];
}
Hope it works..
This is the situation...
I have UIViewController, I want to programatically, without any buttons, to go to my Tab Bar Controller or to one of my Table View Controllers.
This is what I did so far:
UIViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
[self dismissViewControllerAnimated:NO completion:^{
[self performSegueWithIdentifier:#"appLaunched" sender:self];}];
}
This does not work, I made a segue and gave it an id, but the issue remains, my app when launches just shows a white screen and the transition is never made. Can anyone help me please?
Thank you.
Perhaps try something like
- (void)viewDidLoad
{
[super viewDidLoad];
[self pushIt];
}
- (void)pushIt
{
[self.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:#"appLaunched"] animated:YES];
}
There are 3 view controllers View1,View2 and View3.
From view3 I have to navigate to view1.
I have tried the following code but it doesn't work.
//in View3.m
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
{
appDelegate.isComingFromCountries = YES;
[self dismissViewControllerAnimated:YES completion:nil];
}
//in View2.m
-(void)viewWillAppear:(BOOL)animated
{
if (appDelegate.isComingFromCountries == YES)
{
appDelegate.isComingFromCountries = NO;
[self dismissViewControllerAnimated:YES completion:nil];
}
}
But this code doesn't work. How do I handle this?
You can use use presentingViewController for dismissing it,
try this -
[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES];
A -> B -> C
Running the above code in modal C will take you back to A.
You have to use delay method to perform animation so that main thread should start performing in B viewController
[self performSelector:#selector(methodForDissmiss) withObject:nil afterDelay:0.5];
then write dismiss code in selector method to work by your logic.
If you are returning to the root view controller from a series of modally presented view controllers then the following code will work in iOS6
[self.window.rootViewController dismissViewControllerAnimated:NO completion:nil];
I think, It may help you. According to your code( in comments area), You second view controller push from first view controller, then present third from second. So you have to set delegate as second in third. And do your code as below in third VC.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
{
appDelegate.isComingFromCountries = YES;
[self dismissViewControllerAnimated:YES completion:^{
[self.delegate dismissModal];
};
}
In SecondVC.m
-(void)dismissModal
{
[self.navigationController popViewControllerAnimated:NO];
}
Also you can pop to view 1 from view 3 on like this:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
[self.navigationController dismissViewControllerAnimated:NO completion:nil];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
You can try this one :
if you are pushing one viewController to another and want to move back then use this one
[self.navigationController popViewControllerAnimated:YES];
if you are presenting viewController use modelly and want to move back then use this one
[picker dismissViewControllerAnimated:YES completion:nil];
also you can try this because first you need to dismiss third viewController then second one.
UIViewController *viewController = [self parentViewController];
[self dismissModalViewControllerAnimated:NO];
[viewController dismissModalViewControllerAnimated:YES];