ios - how to move to a particular UI viewcontroller - ios

in my app i have a tabbar. The UI tabbar controller has five indexes. Each indexes consists of 5 UI view controllers.
In some conditions if i click a button i want to open a particular view controller placed in the 0th index of the tab bar.
How to open that view controller alone directly, pls help me friends....

You can send the index of the tab you want to select with your push notification (see here http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1 for more info)

first add a view as subview to the tabbar and then hide and show the view whereever you needs
UIView *firstview=[[UIView alloc] init];
[tabbarObject.view addsubview:firstview];
tabbar object i added to window
[self.window addsubview:tabbarObject];

Related

Why Tab bar is going to hide when Push to another View in objective c

I am using TabBarController with four tabs in my applicatin. In the second Tab I'm using PageViewcontroller. PageViewController contains Five pages. Where the first Page view contains the button. On button click we can navigate to another view. When we navigate to another view, the tab is going to hide.
But I don't want to hide the Tab bar.
Anyone can please help to resolve this problem.
Thanks
In order to make UITabBar visible in all the screens of your app you need to take UINavigationController for all the tabs, UINavigationController will be the viewControllers with relational segue and UINavigationController's root view controllers will be your initial controllers which you want to show on Tabs
Below is the screenshot of how you design it using your storyboard
And here is how it works
Deselect Hide bottom bar on push as below :
Or programatically :
yourViewController.hidesBottomBarWhenPushed = NO;

How to load another View Controller on Tabbed application Without losing the tab

I have a Tab Bar application coded in Objective-c. One of the tabviews I have is a TableView. What I'm trying to do is, when a cell of this TableView is selected, the app takes the user to another view, but this view isn't on the tab menu, and I don't want to lose the tab menu when this view appears.
Is it possible to do it? How? Couldn't find much on the web.
Just embed navigation controller to that tab's viewcontroller which have tableview.
so your viewhierarchy should be like tabbar controller - navigation controller - viewcontroller (tab) - detailviewcontroller
you can embed navigation controller by selecting viewcontroller, then from menu select editor then embed in then navigation controller.
Hope this will help :)
If you are having the single View Controller to show then you can try doing this by adding the new view controller's view as
subView to the current view controller's view
Eg:
newVC.view.frame = self.view.frame;
newVC.view.frame.size.height = self.view.frame.size.height - HEIGHT_OF_TAB_BAR;
[self.view addSubview:newVC.view];
If there are more View Controller's that are adding further then
using the navigation controller under tab bar controller will also
work.
Refer: How to implement tab bar controller with navigation controller in right way

Add invisible tab to App?

I have a Tab App with 3 tabs. The tab view controllers all link to the Tab Bar Controller.
However, I don't necessarily need a 4th tab, but, I need a hidden view that the user can only access by clicking a button on another view.
How should I go about doing this?
Usually, I create a view controller and create a relationship to the tab bar controller and set the view controller class.
However I do not want to see a fourth tab for the hidden view.
Note that the fourth view should still be showing the tab bar when it is loaded and visible.
Thanks
I would do this by making the 4th controller a child view controller of MainMenu. You can do something like this in your button method:
self.vc4 = [[FourthViewController alloc] init]; // or some other way to instantiate your controller
[self addChildViewController:self.vc4];
[self.vc4 didMoveToParentViewController:self];
[self.view addSubview:self.vc4.view];
self.vc4.view.frame = self.view.bounds;
vc4 would be a strong property of type FourthViewController.

How to create a UIView with NavigationBar and TabBar

I would like to introduce in my app a View that will contains both navigation bar and a tab bar at the bottom. View contains a Table View with multiple entries and once user tap on a cell a push segue takes him to another view with details regarding the cell he has previously tapped. If he decides, user can go back to parent view by tapping on 'Back' button of the navigation bar on top. In addition to this, I would like my view to have a tab bar at the bottom with extra tools for the user. So, if he decides to check the 'Creator' of the app, he can by simply tap on 'Creator' TabBarItem at the bottom.
I would like to ask you what is the best way to achieve the above. I have already tried to use UITabBarController combined with UINavigationController. Didn't achieve what I was looking for because I would like the view with the table on it to be independent from the TabBarController and NOT a part of it (by part I mean by accessible through tabs).
Do you believe a UINavigationController view with UITabBarView would be a better choice?
UPDATE
What I mean by, "independent from the TabBarController and NOT a part of it":
Once the app loaded, I would like to see my main view (with table) contains Navigation Bar on top and Tab Bar at the bottom. However, I don't want to see the first tab of the Tab Bar selected because my main view will not be accessible through tabs of the Tab Bar but through Navigation Bar. If, for example, I am in Main view and tap on 1st tap, I would like to move to another view that will contains some other info.
Option 1:-
Create a tab bar Controller and on that TabbarController assign your navigation Views.
say nav1 with tab1 , nav2 with tab2...
Option 2:-
Create a Navigation View Controller and than add the tabbarcontroller on that navigationView Controller by using addSubView.
So when the user clicks on a row in a table u will go to a different View which doesn't have the TabbarController and when the user comes back he will again see the TabbarController.
This is what I will do:
First I will subclass UITabbarController and create for example ParentTabBarController. This controller will contain all the tabs necessary and what they will do if they are clicked so on.
Next for each viewcontroller I create, I will subclass from this ParentTabBarController so that the tabs are already in. You can add additional functionality or override it depending on your situation.
In your appdelegate pass in a navigation controller and every time push and dismiss the viewcontrollers you created in second step.
Hope this helps..

Using UINavigationController view

I would like to better understand the use of UINavigationController's.
I have setup a new project with a UINavigationViewController, as well as two other view controllers.
In my app delegate I have the following:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
firstViewController = [[NCTFirstViewController alloc] initWithNibName:#"NCTFirstViewController" bundle:nil];
navController = [[NCTNavViewController alloc] initWithRootViewController:firstViewController];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
Within my UINavigationController.m file I can set the title and set up buttons, but this does not work.
This only works if I setup the self.navigtionController items in the actual View Controller itself. Is this correct, or is there something I should be doing in the UINavigationController to get this to work.
Ideally I am looking for a UINavigationController that handles all the pushing to other controllers. In the long run it would be used as a menu system. So if the user clicks a button at the top, they are pushed to a new View Controller but without the back option, simply the same menu items in the navigation bar at the top, which shows a new center view controller.
The issue I am having is understanding how this is setup. If I have to setup this in the view controllers itself, would they all not duplicate the same code. Of course I could setup all the 'movement' in the AppDelegate, but this doesn't seem correct and would pack up the App Delegate itself.
If you look at the UINavigationController class reference, it says (emphasis added by me, but you should read it all so that you understand how this works):
Updating the Navigation Bar
When the user changes the top-level view
controller, whether by pushing or popping a view controller or
changing the contents of the navigation stack directly, the navigation
controller updates the navigation bar accordingly. Specifically, the
navigation controller updates the bar button items displayed in each
of the three navigation bar positions: left, middle, and right. Bar
button items are instances of the UIBarButtonItem class. You can
create items with custom content or create standard system items
depending on your needs. For more information about how to create bar
button items, see UIBarButtonItem Class Reference.
The bar button item on the left side of the navigation bar allows for
navigation back to the previous view controller on the navigation
stack. The navigation controller updates the left side of the
navigation bar as follows:
If the new top-level view controller has a custom left bar button
item, that item is displayed. To specify a custom left bar button
item, set the leftBarButtonItem property of the view controller’s
navigation item.
If the top-level view controller does not have a
custom left bar button item, but the navigation item of the previous
view controller has a valid item in its backBarButtonItem property,
the navigation bar displays that item.
If a custom bar button item is
not specified by either of the view controllers, a default back button
is used and its title is set to the value of the title property of the
previous view controller—that is, the view controller one level down
on the stack. (If there is only one view controller on the navigation
stack, no back button is displayed.)
The navigation controller updates
the middle of the navigation bar as follows:
If the new top-level view controller has a custom title view, the
navigation bar displays that view in place of the default title view.
To specify a custom title view, set the titleView property of the view
controller’s navigation item.
If no custom title view is set, the
navigation bar displays a label containing the view controller’s
default title. The string for this label is usually obtained from the
title property of the view controller itself. If you want to display a
different title than the one associated with the view controller, set
the title property of the view controller’s navigation item instead.
The navigation controller updates the right side of the navigation bar
as follows:
If the new top-level view controller has a custom right bar button
item, that item is displayed. To specify a custom right bar button
item, set the rightBarButtonItem property of the view controller’s
navigation item.
If no custom right bar button item is specified, the
navigation bar displays nothing on the right side of the bar.
The
navigation controller updates the navigation bar each time the top
view controller changes. Thus, these changes occur each time a view
controller is pushed onto the stack or popped from it. When you
animate a push or pop operation, the navigation controller similarly
animates the change in navigation bar content.
So, to do what you want, you do need to set the title and buttons in each view controller. The easiest way to set the title is to set it in the storyboard/xib, or in code when you create it.
You should also replace the root view controller instead of pushing the view controller onto the navigation stack so that you don't keep adding view controllers to the stack. This also avoids displaying the back button, and you won't need to explicitly get rid of it. You would do this by using the setViewControllers:animated: method like this:
[self.navigationController setViewControllers:[NSArray arrayWithObject:theNewViewController] animated:YES];
There is only one NavigationController and this NavigationController controls all the ViewControllers. So barButtonItems and titles are set in each ViewController, you should not set them directly to a NavigationController.
If you want to push a new ViewController and won't push back, I think this may cause some problem because the NavigationController is using a Stack to handle all the ViewControllers. Seems that you will push a ViewController in the stack but not pop it, and maybe you will get some behavior you don't want.
If you still want to implement this, I think you cannot avoid do similar setting in different ViewControllers.

Resources