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.
Related
I'm working on my first iOS app and I'm realizing just right now that I don't have a navigation controller. Since I'm already pretty far in the app and not completely sure of how I would implement a navigation controller, I was wondering if I would need one in order to implement a search controller, meaning a UITableViewController with like a navigation bar on top.
To implement a Navigation Controller you just need to select the View Controller in storyboard then Click up top Editor -> Embed In -> Navigation Controller. You could also just add a navigation bar to the top of the View Controller you are using.
These are the two options for adding a navigation bar, however, neither is required for adding a search bar.
You do not need to add a navigation controller just to display a navigation bar. Navigation bar can be added to any UIViewController.
You can also add just the search controller in a navigation controller, without affecting your other view controllers. This will add a Navigation bar to the search controller and also allow you to navigate to (Push) other view controllers.
I've searched for a suffice answer to this question but I've been unable to come across one that fits my dilemma. How do I implement a tab bar within my already single view application? My storyboard consist of four view controllers, a navigation view as the initial view, and 3 following table views. Now i know the order of containment must have the tab bar controller first so i embedded my navigation controller with a tab bar controller. doing this has given every view controller on my storyboard a dark gray tab bar silhouette on the bottom of each view, so i have no way of manually editing and selecting my tab bar views.
My goal is to assign my third table view controller in my storyboard as the first tab bar item. how should i do this programmatically? the first view controller acts as the default for the tab bar item. how do i change this programmatically?
here is screenshot of my storyboard:
https://41.media.tumblr.com/c3146efea93d2aeeccdcc55a6104674d/tumblr_nqqlieVI8f1tupbydo1_1280.png
here is the documentation provided by apple on the correct coding to properly assign and configure your views but its very depreciated:
https://40.media.tumblr.com/172a516075baed44cde104abf50d91aa/tumblr_nqqmngJLoA1tupbydo1_1280.png
I'm new to iOS, but I know the basis. I want to host 3 UITableViewController in a UITabBarController using the storyboard.
I dragged a UITableViewController from the object list(?) and control dragged creating a seguel. Now the tab shows successfully the table view controller.
The issue is the rows are taking the space of the status bar. So I want a navigation bar(?) there, with a title. Since I'm new to iOS I don't know the following:
Given the fact that UITabBarController is the first controller ever, the hosted UITableViewController should not have a back button, obviously. So is it correct to use a navigation bar to display a title (and possible add/edit buttons)
If so, I tried dragging the Navigation Bar but it doesn't work.
What am I missing or doing wrong?
hope this helps
actually it is done for another answer. but it will be handy to u too
You will want to add in 3 UINavigationControllers. Have each tab in the tab bar controller segue to a different navigation controller. Then set the root view controller for each navigation controller to one of the table view controllers.
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];
My app consists of following:
Tab bar controller with 5 tabs (this is my init controller)
each tab bar item has navigation controller and another view controllers further in
Now, I'm implementing skype-like chat (table view with contacts and chat as a detail view of this table view), which is currently residing in my second tab bar item, about 2 views deep in hierarchy.
When I receive remote notification, I want to preserve user navigation stack in all tabs, so instead of recreating tab bar in appdelegate, I just want to get reference of my navigation controller, that is in my second tab (so that I can modify it's navigation stack later on).
My problem here is, that I just can't get the reference. I got my tab bar like:
UITabBarController *myTabBar = (UITabBarController *)self.window.rootViewController;
but then I don't have any clue what to do. I will be happy for any suggestion.
The answer is (UINavigationController*)[myTabBar viewControllers][1] :)