How to TabBarController display differents Items? - objective-c

On my firstViewController I have a tabbar that contains my firstViewController and a helpViewController.
When I click on a button from the FirstViewController, I push a NewViewController. But, when this view is pushed, I want to change the content from the TabBarController to display other ViewControllers, like infoViewController, optionViewController and NewViewController. Is that possible?
The First Image represents my application. The FirstViewController has a button that will push the NewViewController. When the user clicks this button, I want that my app shows what is in the second image. Is possible?

Yes, this is possible (I just did a proof of concept in Xcode). Assuming that you are using storyboarding, you need to make your initial view controller a UINavigationController otherwise you won't be able to use the push segues. Then, make the first UITabBarViewController the root view controller of the navigation controller. Put an entirely new UITabBarController into the storyboard, and then put a UIButton into the firstViewController and link it via a push segue to the new (second) UITabBarController.
When you tap the button the old tab bar will slide off, and the new one will slide on.
Here's an example of how it all looks:

!!This app uses navigationController and TabBarController!!
Using the storyboard I saw each piece of the app, then I had the Idea: Insted of pushing the NewViewController, how about push a tabBarController? When the user clicks the button, the app will push the tabBarController with 2 TabController`s.
Just add New File to your project, sub classed UITabBarController. Then add this code to the init method of your tabBarController: self.hidesBottonBarWhenPushed = YES;
On ViewDidLoad just alloc and init what views you want to display on the tabBar and
self setViewControllers:[NSArray arrayWithObjects: vc1, vc2, vc3, nil]];
Working fine here :D

You can nest TabBarControllers. But that would look strange. And the first TabBar wouldn't be changed. Pushing a TabBarController into a TabBarController is not possible because TabBarController does not support pushViewController. Thats only possible with a NavigationController.
Anyhow you can change the content of the TabBar completely programatically.

Related

Edit Button in UITableViewController when in Popover

I'm displaying a UITableViewController inside a popover. Everything works fine. Now I want that little "Edit" Button on the top right to reorder the cells. But unfortunately I can't achieve this.
I have implemented the 2 delegete methods for reordering, and in my tableviewcontroller I call this on viewdidloead
[self setEditing:YES];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
but for some reason I can't see the navigation bar on top that should display the edit button.
what am I doing wrong?
thx in advance
you can create your UITableViewController in the same way you did it now, embed it in an UINavigationController using – initWithRootViewController: and show the navigation controller in the popover

Pushing a navigation controller is not supported- performing segues

I created a new navigation controller in my storyboard (not programmatically!) and set it to be "Root View Controller" to a regular UIViewController and added a button in it which says- forward to the next view controller (this second view controller is a view controller which I want that will have a back button to link to the initial view controller).
Now, whenever I try to link the button to the next view controller- "Pushing a navigation controller is not supported".
Help me please, and thanks
EDIT:
I accidentally subclassed UINavigationController, and not UIViewController in my class.
Thank you anyway.
I've tried this and have no problems, its all done in IB with no additional code required ...
Start a new project, "Single View Application" using story boards
Select storyboard and delete the views its produced.
Drag on a new Navigation Controller (it will bring a table view with it)
Delete the table and the table view controller, so you are just left with the Navigation Controller
Drag on a normal view controller
Right Click and drag from the Navigation controller to the new View and choose "Relationship - Root View Controller"
Drag a "Bar Button Item" on to the Navbar which should be visible on the top of your ViewController, you can rename this Forward if you wish.
Now drag on another view controller which is the one your "Forward" button will push in to view.
Right Click and drag from the bar button to the 2nd View Controller, and choose "Push"
Run the project and you will get a Single view with a Navbar and your button, clicking your button will Push the other view and give you a Back Button to return to the first View Controller. I'll try and post a picture of my storyboard if it helps.
Plasma
I had the same trouble. I wanted to have a navigation controller on each storyboard, so that each could run independently, be individually debugged, and so that the look would be right with the navigation bar.
Using other approaches, I found the UINavigationController would be retained from the original storyboard -- which I didn't want -- or I'd get errors.
Using the AppDelegate in your view controller to set the rootViewController worked for me (borrowing segue naming conventions from Segue to another storyboard?):
- (void)showStartupNavigationController {
NSLog(#"-- Loading storyboard --");
//Get the storyboard from the main bundle.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Startup" bundle:nil];
//The navigation controller, not the view controller, is marked as the initial scene.
UINavigationController *theInitialViewController = [storyBoard instantiateInitialViewController];
NSLog(#"-- Loading storyboard -- Nav controller: %#", theInitialViewController);
//Remove the current navigation controller.
[self.navigationController.view removeFromSuperview];
UIWindow *window = [(AppDelegate *)[[UIApplication sharedApplication] delegate] window];
window.rootViewController = theInitialViewController;
To swap views Programatically you would need to select the segue and give it an Identifier like "PushView" then call it like this ....
[self performSegueWithIdentifier:#"PushView" sender:self];
That will programatically do the same as clicking the forward button. I've created you an example project with the code discussed above. Has an -(IBAction) with code in you can use for programatially changing the view.
PushView.zip
I also wanted to do this, present a screen (that had an embedded navigation controller) when the user pushes a button.
At my first attempt, I connected the segue from the button in the fist screen to the Navigation Controller, and the app was crashing with this error "Pushing a navigation controller is not supported".
This is the solution I found:
Select the segue from the button in the first screen to the navigation controller.
If it had an identifier, copy its name. Then delete that segue.
Then create a new segue by CTRL-clicking the button in the first view controller and dragging to the VIEW CONTROLLER YOU WANT TO PRESENT (not to the Navigation Controller that is pointing at it), and select Push in the small pop up window.
Then click the icon in the middle of the segue and paste the name you copied in the first step as an identifier for it.
IB is going to give you a warning "Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:." Don't worry, it works perfectly.
If you want to customize the string that is shown as the Back button to return, you can add this line in the viewDidLoad method OF THE VIEW CONTROLLER THAT IS BEING SHOWED AFTER THE BUTTON IS PRESSED, that is the Child view controller.
(replace "Settings" with the name you need)
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.topItem.title = #"Settings";
...
}

ios sdk only one view changes at a time bug

I'm pushing a number of views:
the top one is a UITabBarController
the second one is a UINavigationController with a pushed view
the third one is a modal box.
Once the close button in the modalbox is pressed I'm trying to revert everything to the default state and change the tabbar index.
[self dismissModalViewControllerAnimated:YES];
[self.navigationController popViewControllerAnimated:NO];
[self.tabBarController setSelectedIndex:3];
This dismisses the modal view but doesn't do anything else. Any ideas what could be wrong? I read something about a possible ios bug but I don't know how to work around it.
Neither UITabBarController nor UINavigationController is a view. Both are subclasses of UIViewController and have a property NSArray *viewControllers.
If you have an actualView controlled by an ActualViewController that is pushed on top of a rootView controlled by a RootViewController that is the rootViewController for the navigationController, and you also have a modalView controlled by a ModalViewController, then put
[self dismissModalViewControllerAnimated:YES];
in ModalViewController.m, and put
[self.navigationController popViewControllerAnimated:NO];
in ActualViewController.m (from whence modalView is pushed, presumably), and put
[self.tabBarController setSelectedIndex:3];
in RootViewController.m (from whence actualView is pushed, presumably).
If modalViewController was never added to the navigationController, then it doesn't know that the navigationController exists.
If actualViewController was never added to the tabBarController, then it doesn't know that the tabBarController exists.
The easy (and dirty) way:
Dismiss the modal view in the modal view. Make the navigation view controller the delegate of the modal view. Make the tabbar controller the delegate of the navigation controller. When the button is pressed call a method in the navigation controller that pops the view and calls a method of the tabbar controller which changes the selected tab.

How to add a navigation bar to a UITableView

I added a subview to my application. The view controller is a UITableViewController. When I open the .xib file I see the table, but I can't drag a navigation bar onto it. So once the user enters the view, they have no way of getting back to the previous screen. What can be done?
the UITableView nib representation cannot have it. You can simulate the UI in the case you have a navigationController.
If you want to have a navigation controller, your UITableView has to be pushed into the stack of navigationController.
Assuming your view controller is ViewControllerA has a navigationController, then this method will make sure you have navigation controller in your UITableView:
[viewControllerA.navigationController pushViewController:tableViewController animated:YES];

keyboard not appearing when uitextfield is pressed

I have presented a navigation controller (Nav1) as modal view controller from rootViewController
Then from Nav1 i created another navigation controller (Nav2) and presented it as modal view controller.
In nav2 when i click a table cell it pushes a view controller containing UITextField
Now the problem is when I click on UITextField it does not show iphone keyboard
Actually I am trying to make something like alarm label as in iphone clock app.
Just be sure for you have set the delegate the textfield...
[textField setDelegate:self];
why did you choose two nav controllers?
you can use tabbarcontroller by the way there is much more simpler way to achieve this.Search on google
check if
"reloadData"
is not executing before the UITextField becomes active