UINavigationController popToRootViewController and P - iphone

I am working on app with UINavigation.
First view has two buttons, 'AddNew' and 'Show All'.
flow of app is :
When user selects first view, it will push ViewController with textView and a button.
This view will push another view controller with tableView to select one of the items,
after selection, this view push a viewcontroller with summary of selected Items and a button to save options.
When user tap on save button, it will do some calculations according to selected data, save values in database and pop to root view controller and open show all viewcontroller.
My Problem :
I tried using poptorootviewcontroller on save button and pushviewcontroller on firstView's viewdidappear (checking with flag). but it seems that navigation controller's animation is not completed when I tried to push viewcontroller.
I also tried poptorootviewcontroller without animation, but not working.
I also tried on viewdidappear of firstViewcontroller, performselector:afterDelay: but still no success.
What is the best way to achieve this?
Thanks,

Related

Multiple instances of the same TabBarController after Modal Segue iOS

I have an app with one main TabBarController containing two tabs that control two different views, A & B. View A is a scrollView and View B is a TableView. When i initially load the app, the scrollview in view A is empty.
In order to add pages to my scrollView, I have set it up as follows: I go to view B and perform one modal segue to a view embedded with a navigationBar. The navigationBar only has one button, 'Cancel', which I use to dismiss the view. Otherwise, the user must click on an image an perform another modal segue to a different view. This view has no navigation bar, and has one button 'DONE', which I use to perform a modal segue back to the initial tabBarController.
Here's the problem: the page is added to the scrollView with no errors after I press 'DONE'. However, I believe I now have two instances of the same tabBarController floating around in memory. When I attempt to grab the views contained in the scrollView with a different button, it tells me that it is now empty (even though it was full during viewDidLoad and viewDidAppear).
How can I remove the initial tabBarController view or otherwise how can I segue back to the tabBarController that I have already allocated? Any help would be extremely appreciated! Thanks!
You shouldn't do a segue back to the original view controller. Rather, you should dismiss the current view controllers animated, and show your original tabBarController.
Inside the view you were segueing back from, add:
tabBarController *tabs = (tabBarController*)[[self presentingViewController]presentingViewController];
tabs.selectedViewController = [tabz.viewControllers objectAtIndex:0];
[[[self presentingViewController] presentingViewController] dismissViewControllerAnimated:YES completion:nil];
Then you will have the view A appear and still use the same allocation.

Change view controller on press button

I have two View Controllers, I need to have a button in ViewControllerOne that when I press it Show me ViewControllerTwo.
In storyboard I related both views with a "Presenting Segues" - Push modal. And both views have a view controller class.
I'm not sure what you mean by "I related both views with a 'Presenting Segues' - Push modal." Are you using a navigation controller and want a push segue, or do you want to do a modal segue? A "push modal" is a contradiction in terms.
So, let's imagine that you want a modal segue. So, you put a button on the first view, right-click and drag (or control-click and drag) from that button to the second view.
You'll get a pop up asking for type of segue. Select "modal".
And you're done transitioning from 1 to 2. No code necessary.
If you want a button on the second view to take you back to the first view, you do not want a modal segue from the second view back to the first view, but rather you want to dismissViewControllerAnimated. You can do this via a custom segue, or easier, just have a button which calls dismissViewControllerAnimated. Thus, you'd add a button to the second view, and while the editor is in in "assistant" mode (where the associated .h file is showing below the interface builder; see below if you want to know how to show the .h file at the same time as the Interface Builder screen), right-click (or control-click) and drag from the button on the second view down to the second view controller's .h file:
By the way, if you don't see the .h file there, click on the "assistant" editor button and choose "automatic" for the files to be shown down there, and you should be good:
It will then show you a pop up asking you what you want to do. Select IBAction and give your new method a name:
Then go to your code for the view controller, and add the dismissViewControllerAnimated code:
All that code says (and in this example, I just called my IBAction dismissTwo) is:
- (IBAction)dismissTwo:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
If you want to do a push segue, it's even easier. First, if you don't already have a navigation controller, add one by selecting the first view and choose "Embed in" - "Navigation Controller":
When you do this, you'll have a new navigation controller (which you don't really need to do much with) and the first view will have a navigation bar.
Now, right-click (or control-click) on your first view's button and drag over to the second view:
This time, select the "push" segue:
And you'll know that it worked, because your second view will have a navigation controller
You don't need a button to go back, because the navigation controller will automatically have a "Back" button, so you don't need to add your own.
This is how you achieve a push segue.

Iphone Save data and go back to the previous view controller

I have a Table View Controller which I have designed using storyboards. This has an Add button on the navigation bar and I created all this using storyboards. On Add button clicked I have a view controller view to add data and this has a save button on the navigation bar. On Save button Clicked I want the user to save data and return to the TableViewController. All the design was done using storyboards. On Save button clicked I am calling the IBAction save method. I am able to save data but how do I go back to the previous TableViewController programmatically.
thanks
prerna
In your IBAction save method, call:
[self.navigationController popViewControllerAnimated:YES];

UINavigationController doesn't fully push view and only changes the Navigation toolbar to the next view's toolbar

So I have an iPhone application that utilizes a UINavigationController for setting up the views. When the application first starts, it presents the user with a UITableViewController and the user can select an item and it will push another view. Now I have it set so that my app remembers the user's last selection and automatically selects it and loads the correct view controller. The only problem is that I am experiencing a really weird glitch when I load the next view automatically..
When the view is pushed, the navigation toolbar will change so that a back button directed to the previous view is showing but it won't display the next view. It will instead keep showing the table view and I can interact with it as well. I can press the back button and it will change the toolbar back and the tableview is still shown. Then when I select an item it loads the view just fine.
Thanks for the help.
Code:
I determining whether to push the view controller based on whether it can connect to a server. I do this in a backround thread:
- (void)startingThread
{
[NSThread detachNewThreadSelector:#selector(loginThread:) toTarget:self withObject:communicator];
}
- (void)loginThread:(MowerCommunicator *)communicator
{
//If it can connect, launch thread complete.
[self performSelectorOnMainThread:#selector(loginThreadComplete:) withObject:communicator waitUntilDone:NO];
}
- (void)loginThreadComplete:(MowerCommunicator *)communicator
{
//push view controller
}
Now I have added NSLog statements to track if the view is actually "showing" and both viewWillAppear and viewDidAppear get called. I also check the delegate methods for the navigation controller and they get called as well.
I have a view that is the initial startup view and it reads from a server to determine what to display in the next table view. That gets pushed fine and when the tableview gets pushed, I hide the back button so the user can't get back to the first view without closing the app. Then the tableview looks at a variable in NSUserDefaults to determine with there is a saved index and then pushes the next view controller. That is when the glitch occurs. If I then press the back button to "go back" to the table view (this really just changes the navigation toolbar) and then I select an item from the table view, it loads the next view correctly. Also, I call the exact same methods when the user pressed an item from the table view and when the app loads the view automatically.
The simplest explanation is that you're pushing the initial tableviewcontroller onto the navigation controller's stack twice.
If you have the initial tableviewcontroller set as the nav's first controller in a nib but then you push the same controller onto the stack when trying to automatically display the stacked views, you would get what you are describing. The nav starts out with the controller from the nib and then you push another instance on top of that.
You should log the nav's viewControllers property before and after you do the automatic push to see what the actual state of the stack.

Use two TabBarController

I want to use two different TabBarController. Everything is declared in my AppDelegate. Here is the result :
TBC1Tab1 | TBC1Tab2 | TBC1Tab3 and then when I push a button my new TabBarController : TBC2Tab1 | TBC2Tab2
Each Tab is linked to a view. I use a button on my first tab to go to my second TabBarController with my new tabs. My problem is to go back to my first TabBarController : how to do it ?
So to have my "back" button I add my code in my views. Then if I use my back button I can't go back to my first view from my first TabBarController.
Here is what happens : my view inside my second TabBarController (which is linked to my tab) disappear but my TabBarController doesn't disappear so I can't see my first view with my first TabBarController.
Someone know how to do it ? If you don't understand I will add some pictures. thanks
you need to use two methods in your app delegate
one will work by clicking on your button in tab bar and other will work by clicking on back button
make sure your back button should not be navigation controllers back bar button
that must be custom button
if u have any problem in putting your custom button in the place of back button
put it in right part
thats it other wise if u want to come back it wont work because
navigation controller is the child class of tab bar controller
in NSObject
so
if u want to try with custom button i think u know the answer
other wise call again previous method view did load in 2 nd button