When loading view tab-bar not displayed - noob question - iphone

I Have a TabView control, and when the user clicks on the tab item, the view will load.
When the view is loaded, there is a button on the view, and when i click on the button, another view gets loaded, i used the following code to load the view:
NextView *next = [[NextView alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:next animated:NO];
But when the view loads, the tab bar items are not displayed. It loads on top of the tab bar items. how can i make the view pop out with the tab bar items ?

NextView *next = [[NextView alloc]initWithNibName:#"yourNibName" bundle:nil];
[self presentModalViewController:next animated:YES];
if you are using presentModalViewController then you can't display the tabBar instead you can use pushViewController

Related

Want to create logout button in tabbar

I have created an application that have 9 screen and I have added tabbar in it which contain 4 baritem.
Now I have two problems -
1 => My last baritem is logout button, I don't want to display view controller for it, simply when user click this button then alertview should pop up and ask for logout and if user says yes then it will logout.
2=> How to display tabbar in that view controller that does not added in tabbar, because I have 9 screen and only 4 screen display in tabbar.
UPDATE
I said that I have 9 view controller in my app
like...
firstViewController
secondViewController
thirdViewController
fourViewController
|
|
ninthViewController
But my tabbar have only four view controller in baritem which are -
firstViewController
secondViewController
thirdViewController
fourViewController
Now, my other view controller does not display tabbar.
I dont know this is right way or not but you can do it like this...
first read this question that show how to display login and come back to home.
Now add this code in didFinishLaunchingWithOptions method
UIViewController * logoutVC =[[UIViewController alloc] init];
NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:firstView, secondView, thirdView,logoutVC, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:YES];
[self.window addSubview:self.tabController.view];
And implement this delegate method of tabbar
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
//select the index where your logout button is
if ([tabBarController selectedIndex] == 3) {
NSLog(#"logout");
self.tabController.selectedViewController = fistView; //firstview is your home screen
//LOGOUT
LoginViewController * vc = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
vc.delegate = self;
[self.tabController presentModalViewController:vc animated:NO];
}
}
Your first question:
Don't do this, it's an abuse of tab bar controller. Each item on the tab bar controller should be a different view in your app, not an action. Find an appropriate place for a logout action button.
Your second question:
There are several ways to show a view controller that isn't one of the main VCs for the tab bar controller. It could be reached by:
being shown as a modal screen
as a popover
Update
To show a 'secondary' view controller that isn't a main VC of the tab bar, but still have the tab bar visible, you can present that secondary VC as a sub-viewcontroller of a main tab bar VC. In other words, present the view of your secondary VC as a subview of a main VC view.

UISplitViewController popover is blank

I am using UISplitViewController with UITabbarController as master view and navigation controller as detail view. Each of the tabs on the master view contain a navigation controller. When any of the tabs on the master view are selected, a view is pushed on the detail view navigation controller.
recentsviewController = [[RecentsViewController_ipad alloc]initWithNibName:#"RootViewController" bundle:nil];
recentsNav = [[UINavigationController alloc] initWithRootViewController:recentsviewController];
//similarly rootNav and favNav
NSArray* controllers = [NSArray arrayWithObjects:recentsNav,self.rootNav,favNav,nil];
self.tabbarController.viewControllers = controllers;
detailViewController=[[LoginViewController_ipad alloc]init];
detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];
splitViewController =[[UISplitViewController alloc]init];
splitViewController.viewControllers=[NSArray arrayWithObjects:self.tabbarController,self.detailNav,nil];
splitViewController.delegate = self.detailViewController;
[self.window addSubview:splitViewController.view];
[self.window makeKeyAndVisible];
This seems to work fine. When app goes into portrait mode a 'Browse' button is added to the navigation bar. Clicking this button shows the hidden view along with the tabs perfectly fine. I can switch between the tabs and work on the views displayed in the popover. When tapped on other than popover area the popover is dismissed as expected.
The two things that are not working are
The popover has to show up on its own each time app switches to portrait mode without the user having to select the button added to nav bar
On some occasions I need to dismiss the popover programatically.
I have tried foll code :
- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {
barButtonItem.title = #"Browse";
[[self navigationItem] setLeftBarButtonItem:barButtonItem];
self.appDelegate.rootPopoverButtonItem = barButtonItem;
self.appDelegate.splitViewPopover = pc;
[self.appDelegate.splitViewPopover presentPopoverFromBarButtonItem:self.appDelegate.rootPopoverButtonItem permittedArrowDirections:UIPopoverArrowDirectionUp animated:NO];
}
This adds a black translucent popover each time the orientation changes. How do I make it show what the browse button shows when it is clicked?
The usual dismissPopvoerAnimated does not seem to work here.
Any help is appreciated.
Using performSelector:withObject:afterDelay: fixed the issue

Need to hide bottom bar in tab bar navigation based application

I'm having problem in Tabbar-Navigation based application. I have a tab bar with 3 tab bar button items.
Each Tab bar item, I need to show the Navigation controller's view. When I click on the first button, I need to show Navigation controller's root view.
I need that when navigation controller's view is pushed, then in one view I need to show tab bar. When second view is pushed, I need to hide tab bar. When third view is pushed, I need to show tab bar again. It should also work when the view is popped up.
In Navigation controller's root view (Main view), I need to show the tab bar at bottom. But a new view (first view) is pushed then I need to hide the tab bar. Then I have set the property hidesBottomBarWhenPushed to YES.
FirstViewController *firstController = [[FirstViewController alloc]initWithNibName:#"FirstViewController" bundle:nil];
firstController. hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:firstController animated:YES];
It works fine with the first view.
But the problem is when I push a new view (Second view) , tab bar is not shown even if I set the property:
SecondViewController *secondController = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
secondController. hidesBottomBarWhenPushed = NO;
[self.navigationController secondController animated:YES];
Let me know if this works.
FirstViewController *firstController = [[FirstViewController alloc]initWithNibName:#"FirstViewController" bundle:nil];
//firstController. hidesBottomBarWhenPushed = YES;
[self.navigationController presentViewController:firstController animated:YES];

iOS Jump to different view

I have a navigation based app. The root view is a list of items. From this root view you can tap on a table cell to an item's detail view. Or you can go to a form view to create a new item via the 'Add' button in the nav bar.
My question is how I can jump from the form view to the detail view once the new object has been created?
I don't want to push the detail view on top of the form view, because I want the root table view to be what the user see's after pushing the 'back' nav button form the detail view.
I've tried the following. It pops to the root view fine, but doesn't push the detail view after that..
[context save:&error];
[self.navigationController popToRootViewControllerAnimated:NO];
// display detail view
GoalDetailViewController *detailViewController = [[GoalDetailViewController alloc] initWithNibName:#"GoalDetailViewController" bundle:nil];
// Pass the selected object to the new view controller.
detailViewController.goal = goal;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
Any help and direction would be much appreciated :)
Cheers!
Generally you would implement the add button using a view controller displayed modally.
[self presentModalViewController:modalViewController animated:YES];
meaning it appears from the bottom of the screen (see adding a contact). Then when they press done in the top right you can push the detail view controller on the navigation controller without animating it, making the back button go back to the original list view.
This isn't something you see too often in apps, but it can be accomplished like this:
// Get the current view controller stack.
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
// Instantiate your new detail view controller
GoalDetailViewController *detailViewController = [[GoalDetailViewController alloc] initWithNibName:#"GoalDetailViewController" bundle:nil];
detailViewController.goal = goal;
// Remove the topmost view controller from the stack
[viewControllers removeLastObject];
// Replace it with the new detail view controller
[viewControllers addObject:detailViewController];
// Change the view controller stack
[self.navigationController setViewControllers:viewControllers animated:YES];
// Clean up
[detailViewController release];
Exactly what animation you get is described here.

popView from UITabBarController inside UINavigationController

I'm building an application based on the Utility template from Xcode, to which I have added some more views. My application structure would be as follows:
MainView (the app menu)
Flip-side view (a calculator)
UINavigationController
Settings view
viewDiDLoad: UITabBarController
- Tab1 view (options)
- Tab2 view (information text)
I can navigate correctly from my MainView to my Flip-side view, which is also the root view of the Navigation Controller. From my Flip-side view, I push a second view of my Navigation Controller (Settings view) that is configured to show an UITabBarController, with two tabs, as soon as it loads (with viewDidLoad).
If I remove the UITabBarController, I can return with no problems to my Flip-side view using "popViewController" from my Settings view. The problem comes if I load the UITabBarController in viewDiDLoad in my Settings view... the tabs work perfectly, but I'm not able to return to my Flip-side view (root view of the Navigation Controller) anymore.
I CAN return if I use the Navigation Bar of the Navigation Controller, but I want to configure my own buttons and have the Navigation Bar hidden.
So far I've tried the following methods:
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
[self.navigationController popToViewController:FlipSideViewController animated:YES];
But they don't seem to work. The first two just do nothing (the screen remains as it was), and the third one does not recognize the "FlipsideViewController" (maybe because it's a delegate of the MainViewController?).
Is there a way to check what is exactly doing the "back" button of the Navigation Bar if I activate it?
Should I be using delegates?
Can I call a popViewController method in my Settings view from any of the two Tab views?
This is my Flip-side view:
- (IBAction)showSettingsView {
SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:#"SettingsView" bundle:nil];
controller.title = #"Settings";
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
This is my Settings view:
- (void)viewDidLoad {
[super viewDidLoad];
tabBarController = [[UITabBarController alloc] init];
Tab1ViewController* vc1 = [[Tab1ViewController alloc] init];
Tab2ViewController* vc2 = [[Tab2ViewController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
tabBarController.viewControllers = controllers;
[self.view addSubview:tabBarController.view];
}
And the method to return in one of the Tab views:
- (IBAction)backFromTab1View {
[self.navigationController popToViewController:FlipSideViewController animated:YES];
}
Thanks very much and sorry if the question is too basic!
I actually solved the problem creating my own UINavigationBar in the Settings view and using:
[self.view insertSubview:tabBarController.view belowSubview:myNavigationBar];
That inserts the rest of the view below the Navigation Bar and I still can use it to configure a button which pops the view and return to the previous screen.
It took me a while to realise the differences between "addSubview" and "inserSubview + belowSubview". Sorry about that!