I am begineer to iOS application development.
My Application flow is like that
It starts as naviagtion controller then after detail page i make custom tab bar as window root controller
now i have 3 tabs
each tab with different ui
means having
tab1 -> table view
tab2 -> grid view
tab3 -> with multiple tables
now i want each ui controller must have it's own navigation bar
and also it crossponds to associate tab.
Thank you for your precious opinion in advance.
Just create the Custom tab bar controller with three navigation controller for 3 tabs.
Then each navigation controller's root view controller should be your corresponding view controller.
For better understanding please review this image.
Programmatically from Tabbarcontroller context
UINavigationController *navCont1;
UINavigationController *navCont2;
UITabBarController *yourTabbarcontroller;
yourTabbarcontroller = [[UITabBarController alloc]init];
FirstViewController *viewCont1 = [[FirstViewController alloc]init];
navCont1= [[UINavigationController alloc]initWithRootViewController:viewCont1];
UITabBarItem *tab1 = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1];
[viewCont1 setTabBarItem:tab1];
SecondViewController *viewCont2 = [[SecondViewController alloc]init];
navCont2= [[UINavigationController alloc]initWithRootViewController:viewCont2];
UITabBarItem *tab2 = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:2];
[viewCont2 setTabBarItem:tab2];
tab.viewControllers = [NSArray arrayWithObjects:navCont1,navnavCont2,nil];
self.window.rootViewController = tab;
Related
I have set Sliding menu(Rear view controller) using SWRevealViewController with a UITabBarController (front view controller). Below is the piece of code I used:
RearMenuViewController *rearViewController = [[RearMenuViewController alloc] init];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];
UINavigationController *navTabController = [[UINavigationController alloc] initWithRootViewController:_tabBarController];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:navTabController];
revealController.delegate = self;
revealController.rightViewController = nil;
self.viewController = revealController;
self.window.rootViewController = revealController;
This works fine and I can toggle between the rear menu and tab bar items using swipe gesture.
But I am not able to set the navigation title for each tab bar item nor I can add any bar button on navigation bar. I can only see blank navigation bar for every tab bar item.
Also would like to share that I am NOT using storyboard in the project.So, I need to set the title and a bar button through code only.
Please let me know if any other info is required.
I managed to access the navigation bar for each tab bar item like this:
UINavigationController *currentNav = (UINavigationController *)self.tabBarController.parentViewController;
UINavigationItem *navItem =(UINavigationItem *) [currentNav.navigationBar.items firstObject];
navItem.title = #"Dashboard";
Need to write this in each item (view controller) of tab bar if we need to have different titles for each tab bar item.
Please let me know if there is a better way to achieve this.
I have a navigation controller which has view controller(VC1) . This view controller has 3 button out of which 1 directs to a tab bar controller. From tab1 of the tab bar controller a button is there which navigates to a View controller(vc2).
The problem is VC2 is not displaying the tab bar. How can I make my VC2 display the tab bar.
Navigation Controller—> View Controller-->Tab bar Controller —>Tab1 -> View Controller (does not show tab bar)
I am doing this in IOS
Using a tabbarcontroller within a navigation controller is not recommended by Apple. However it is possible to do so.
In the VC1, write the following code.
UITabBarController *tabBarController = [[UITabBarController alloc] init];
MyStartViewController *startController = [[MyStartViewController alloc] initWithNibName:#"MyStartViewController" bundle:Nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:startController];
SecondViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
self.viewControllers = #[navController, viewController2];
[self.navigationController pushViewController:tabBarController animated:YES];
Now within startController, add a UIButton. And in the button action, push the new VC2 from it.
Button action:
- (IBAction)buttonPressed {
MyViewController2 *vc2 = [[MyViewController2 alloc] initWithNibName:#"MyViewController2" bundle:nil];
[self.navigationController pushViewController:vc2 animated:YES];
}
Hope this will serve your purpose.
I am creating an application in ios using storyboard. I have a Tab Bar Controller as my root view, from this page I can navigate to other pages using the tabs, but how can I insert any text or image in the root view for the tab bar controller.
The default page (or root page as you are putting it) for a tab bar controller is one of the other UIViewControllers only. A UITabBarController can show another UIViewController inside it. There can be no text or image right inside a UITabBarController, but there can be a UIViewController inside it which has text or images. It is just a container for other view controllers.
Check out this example, it will help simplify things.
FirstViewController *fistView = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:fistView, secondView, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:YES];
In the code above, the firstView controller will be displayed initially in the tabController, so what you want to do is add text and images and stuff inside firstView's xib file (or code).
I'm developing an iOS app which asks the user to either login or signup before using the functionality. The flow is;
The app displays a screen with 2 buttons 1) Login 2) Signup
Upon clicking either button the app navigates the user to different view controllers using UiNavigationController.
Upon successful login the user is directed towards a home view controller which displays a tab bar on the bottom of the view and a UiNavigationController's top bar on the top of the view.
To implement this, I have set the UINavigationViewController as the root view controller in the AppDelegate file.
As soon as the user is authenticated, I push the tab bar controller on the UiNavigationController using the following code.
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
[firstViewController setTabBarItem:[[UITabBarItem alloc] initWithTitle:#"1st" image:[UIImage imageNamed:#"1st.png"] tag:101]];
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[secondViewController setTabBarItem:[[UITabBarItem alloc] initWithTitle:#"2nd" image:[UIImage imageNamed:#"2nd.png"] tag:102]];
ThirdViewController *thirdViewController = [[ThirdViewController alloc]initWithNibName:#"ThirdViewController" bundle:nil];
[thirdViewController setTabBarItem:[[UITabBarItem alloc] initWithTitle:#"3rd" image:[UIImage imageNamed:#"3rd.png"] tag:104]];
UITabBarController *tabController = [[UITabBarController alloc] init];
[tabController setViewControllers:[NSArray arrayWithObjects:firstViewController, secondViewController,thirdViewController, nil]];
[self.navigationController pushViewController:tabController animated:YES];
Is this the right approach?
Someone just said that the using tab bar controller as root view controller will be a better approach.
How can I just set the tab bar controller as root view controller as I dont want to show the tab bar on login/signup screens....
Thankyou!
Just create a protocol, so you can communicate between your login UIViewController and your AppDelegate. Once the login has been done, you can change the rootViewController. You can also get a reference to the AppDelegate, by doing something like:
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
Although I prefer to use protocols to communicate between different objects.
How can we programmatically create a Navigation controller in Detailed view of Split view based iPAd App?
I tried the steps, provided in this link, but could not replace the Detail view controller with Navigation controller in XIB.
I know this is an old question, but i hate questions that aren't answered.
UIViewController * masterController = ... allocation/init ...
UIViewController * detailController = ... allocation/init ...
UINavigationController *detailNavController = [[[UINavigationController alloc] initWithRootViewController:detailController ] autorelease];
UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
splitViewController .viewControllers = [NSArray arrayWithObjects:masterController , detailNavController, nil];