TabBarController called by a TableViewCell in another TabBarController - iphone

I was wondering if it is possible to have the following:
One TabBarController with two buttons containing a UITableView in each one.
Then, if one of the TableView cells is clicked, I would like to push to a new TabBarController with a different set of 4 buttons containing other table views.
Can anyone point me in the right direction?
The first thing I tried was set up the first TabBarController with the UITableView under each button. But when I added the second TabBarController to be triggered from a clicked tableview cell, what I got was the first Tab which contains the 2 buttons, and on top of that, the second tab containing the 4 buttons.
I would like the second TabBarController to replace and leave behind the first one.
I hope I explained myself well enough, thank you for your time.

You should change your push segue to a modal segue.
To go back you are going to need to implement a return button in your destination viewController:
- (IBAction) dismiss:(id)sender
{
[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
}
(note that you must do this in code - you cannot draw a segue line to go back)
At the moment you must have a navigation controller involved in your push segue. When you change to a modal segue you can remove the navController, it won't play a part in the navigation.

Related

Pushed ViewController is "greyed out" cannot intact with it

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.

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.

iOS 5 return to initial nib view resembling a sign out button

this if my first post so please be gentle.
I have an iOS 5 app (using storyboards) where I want the user to have the ability to sign out, and with that reset all settings in the app, and also return the user to the very first nib view.
I have already used this code:
[self.navigationController popViewControllerAnimated:YES];
and the problem with this is that it only sends the user back 1 view and not several.
The issue with this is that I have multiple table views that derive from each other and I want the Sign Out button to remain visible in every single one of these detailed views.
Also, this has to work on both iPhone and iPad (Universal)
Any suggestions?
Thanx.
Why not assign a BOOL value YES on button click, then in the viewWillAppear of each viewController:
(assuming BOOL signingOut)
if(signingOut){ [self.navigationController popViewControllerAnimated:YES]; }
Otherwise, just use:
[self.navigationController popToRootViewControllerAnimated:NO];
Why not set the viewControllers array on the navigation controller.
Or send your logout command to the root controller of the navigation controller and have it pop the navigation controller without animation until there are two left. Then pop the second to last one animated. Then you should still get the navigation animation

Problem in the flow of custom back button when using UIView controller

I am new to iphone development.I have created a button in UIView controller.On clicking the button it navigates to a another UITableView controller .On clicking the row of the table leads to another UIView controller which has also another table in it.On clicking the row of this table leads to another UIWebView.I have created a custom back button placed on the navigation bar of the UIView controllers and UIWebview.On clicking on the back button just leads me to the main page with a button and not to its just previous UIView.
-(IBAction) goemenbutton : (id) sender
{
[self.view removeFromSuperview];
}
The above method is used for all the custom back button.Please help me out to get the correct flow for the back button.Thanks.
You should probably look at using UINavigationController instead of interchanging several views within one UIViewController. The UINavigationController takes care of a lot of things for you, including back buttons with proper titles and nice animations. It also helps you structure your code and gives you more flexibility down the road.
A UIWebview is not a UIViewController and can not be pushed onto the NavigationController. You should probably look at wrapping it into a UIViewController.