Open UIView with navigation history with correct tab - ios

I have some specific question:
My application have 4 tabs with independent navigation controllers under each of it.
Let's say tabs are: "Recent", "Chat List", "Contact" and "Settings". Sometimes I need to open the "ChatView" controller from different tabs and places, like "Contacts" or "Recent". "ChatView" is located under "Chat List" tab (root controller is "ChatListView") and usually is displayed after selecting some existing conversation (in navigation stack it's like ChatListView -> ChatView).
I want to find the best way, how to open the "ChatView" controller with switching to the "Chat List" tab and reseting navigation history, so when user see the "ChatView", the back button we'll turn him to the "ChatListView", but not to "Contact" or some other place where he stayed before. Modal view will not work in this case, because I need both tab bar and navigation bar displayed.
Thank you for your advices!
Update
Also please note that I need to pass some data to the newly opened ChatView controller. Just switching selected tab bar also is not enough, because I need to open View under its root controller (ChatListView -> ChatView)

For this you can use setSelectedIndex property of UITabbarController.

You could implicitly change tab to show by using selectedIndex property.
Try this:
NSInteger indexOfChatsTab = 1;
UINavigationController *chatsNavigationController = tabController.viewControllers[indexOfChatsTab];
[chatsNavigationController popToRootViewControllerAnimated:NO];
[chatsNavigationController pushViewController:selectedChatViewController animated:NO];
controller.selectedIndex = indexOfChatsTab;
Update:
selectedChatViewController from above example is view controller that initialized by necessary data for displaying new chat.
I mean that before pushing you need initialize it like this:
ChatViewController *selectedChatViewController = [[ChatViewController alloc] initWithChatData:chatData];

Related

Connect Tab item to view controller

I have created a custom tab bar on my app delegate but cannot seem to connect them to any particular view controllers. This is where I created the item
YALTabBarItem *item1 = [[YALTabBarItem alloc] initWithItemImage:[UIImage imageNamed:#"nearby_icon"]
leftItemImage:nil
rightItemImage:nil];
But then the app crashes of course because it does not know where to push to. How do I add a view controller to this tab item?
Tab bar items are just the UI representations of the buttons on a tab bar. They don't have an associated view controller, their index on a tab bar do. Normally you use a UITabBarController to handle which view controller to show based on the index of the different tab bar items. You could manage it yourself just using a UITabBar but I'd recommend just using the tab bar controller. You should definitely look at the documentation regarding these classes in order to get a better understanding of how they work.

tab bar controller disappears after modal segue

I am new to this and really struggling, I have searched on here but the answers to this question don't seem to work with what I am trying
the user selects the store name (button) to present modally a new view controller. but then the tab bar controller disappears, and I cannot get it back. Is there a way to add new view controllers that will always have my tab bar controller? i.e. new "tabs", that will only be displayed if the user decides to push the button regarding that tab. I am using Xcode 6.1 with storyboards
I don't know if I got it right, but if you want to show a new View Controller and you want to keep showing the tabs you have you should use a NavigationController inside your TabBarController and then do a push, not present modally;
Your storyboard should look like this:
http://timroadley.com/wp-content/uploads/2012/02/HighLevelStoryboard.jpg
Hope it helps!

Tab bar controller is not showing bar button item

I'm new in Objective-C, and even more using storyboards. This being said I'm trying to use a bar button item within UITabBarController and UINavigationController as can you see in the image below.
But once I run the project in simulator this item is not showing. I would appreciate a non programmatically solution if it's posible.
Okay, so the way to do this:
When you create your tab view controller. You have to add a navigation controller that will handle each tab.
Tab View Controller --> navigation controller --> View Controller 1.
Then add the bar button item to view controller 1. Then go ahead and add the segues.
Now, still it won't show up.
But, if you go to your code for your view controller 1: Add a reference from the storyboard of your bar button item into your View Controller 1 file. Then, in ViewWillAppear():
self.tabBarController.navigationItem.rightBarButtonItem = _btnNewContact;
From there, it will show up and the segue you have configured in your storyboard should work perfectly! =)
After I spent a while trying to get the best way to do it I finally did that I should have done since begin. Read official apple documentation.
Parameters
viewController
The view controller that is pushed onto the stack. This object cannot be an instance of tab bar controller and it must not already be on the stack.
In other words, my approach is just a bad design.

iOS Navigation with side menu

I need to create a navigation in iOS app like following screenshot.
It contains a Tab Bar and a Side menu.
The problem is the right navigation menu button, should be visible in all tabs. Even all inner screens of each tab.
When user selects an option from side menu, it should be displayed on screen.
Now each tab should be accessible from each option item, and each option menu should be accessible in each tab. Its like a many-to-many relationship in DB.
How should I design it?
I have tried following so far.
Within each tab, there is a containerViewController. Which consists of my FrontViewController and SideMenuViewController.
When an option is selected from side menu, a message is passed to containerViewController which removes the old FrontViewController from view and adds new OptionViewController.
The menu button and navigation bar is added in containerViewController, so that if should be visible every time, at any screen.
Problems
Now facing some problems using this approach.
As the navigation bar is added in containerViewController. I have access it using parent property of my FrontViewController. Suppose if I need to use PushViewController in my FrontViewController, I have to use parent property. Like this
[self.parent.navigationController pushViewController:newVC animated:YES ];
[self.parent.navigationController popViewControllerAnimated:YES];
I have to use this approach within each tab. Means code is repeating 5 times.
Can anyone suggest a simple solution. Any help is appreciated.
You can try to use InteractiveSideMenu for your purpose. It supports interactive opening/closing menu and following customization:
Animation duration
Visible content width
Content scale
Using spring animation with params customization
Animation options like animation curve
You should use 3 basic ViewControllers for creating subclasses for implementing your side menu.
MenuContainerViewController is a host for menu and content views
MenuViewController is a container for menu view
MenuItemContentControlller is a container for content that corresponds menu item
Here is an example of setup Host controller.
import InteractiveSideMenu
class HostViewController: MenuContainerViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.menuViewController = self.storyboard!.instantiateViewController(withIdentifier: "NavigationMenu") as! MenuViewController
self.contentViewControllers = contentControllers()
self.selectContentViewController(contentViewControllers.first!)
}
private func contentControllers() -> [MenuItemContentViewController] {
//here is instantiation of content view controllers
}
}
I would think about subclassing UINavigationController and adding your button management logic there. When any view controller is pushed into the nav controller, set its bar button item.
The side menu shouldn't be inside each tab. Your root view controller should really control the main and side views and the main view has your tab controller which has a navigations controller as the root of each tab.
Now that the navigation bar doesn't need to be managed by a different container controller things become easier.
Bar button actions push up to the root view controller only, a reference to it can be set when the navigation controllers are created. Option selection would traverse root VC -> main (tab) VC -> selected tab nav controller -> push.
It could be easier to use a cocoapod for iOS side menus such as APMultiMenu. I've used it and it's simple to use and follow

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..

Resources