UITabBar functionality without UITabBarController - iphone

I have this problem, I've got a navigation-based application, and on the one of the detail view i need to have UITabBar, which will display some UITableViews. Since apple documentation says "you should never add a tab bar controller to a navigation controller" it make quite a problem, i've found this sample: link text, it's working, but after picking one of the table view, the UITabBar disappears.

don't use a tab bar controller, just use a UITabBar inside your controller view and manage the switches between UITableViews yourself, either by:
loading up as many table views as you
need and stacking them (bringing the
one corresponding to the tab bar hit
to front)
switching a single table view's data
source and delegate among a few
helper objects - one per tab in your
bar. When the user clicks a tab, reset the single table view's data source then instruct it to reloadData

Now that you are not using a TabBarController for showing the tableviews (as mentioned in the link), have you made sure that the table views or any other views you are adding when a tab is tapped are correct size?
You are adding a subview or bringing it to top so the table view is probably covering your tab bar.

When they are choosing an item from your table view are you pushing a new view controller onto your navigation controller? If so, you will leave the tab bar behind!
Without some hefty hacking, you generally can't do what you're trying to do. What you'd have to do instead is to deal with adding new views yourself when a table cell is selected so the new views you add don't overlap the tab bar at the bottom. Though this will probably break the navigation controller.
Though my advice is to rethink that part of the app's ui so you don't care that the tab bar vanishes. Sorry :(

Related

Using a Navigation Controller, Page View Controller, and a Tab Bar Controller

I've fairly new to Swift and I've been reading a lot of answers to questions but I'm still struggling to figure this out. For what I'm building, I want the option to swipe between three main pages but I also want a tab bar that serves as an index and another option to navigate between the three pages. Currently I have three main pages that are each embedded in individual navigation views which are embedded in a page view controller. I tried simply adding a tab bar for each of the pages but that doesn't seem very practical. I was reading on orders of embedding but it doesn't seem to be what I want. How would I go about doing this? Thank you!
sounds like a lot of hierarchy but maybe you can try this
Have a single UIViewController that holds your page view controller. Build a custom uiview guy that holds three buttons which will serve as your tab bar and pin it to the bottom of this UIViewController.
For your page view controller, you can proceed as normal and have it hold 3
children. You'll need proper delegation with protocols from: custom tab bar > uiviewcontroller to tell him to move the pages around.

iOS 6.1 Table View Screen Footer

My iPhone app starts off (using a storyboard) with a navigation controller, then a table view controller; what I want to do next is use a tool bar to provide options to go to other table view controllers. The problem is that the tool bar is buried off screen. I would like it to be more like a screen footer, always visible to the user. What is the best way to do this?
The toolbar was originally added to the tableview so as the list got longer the toolbar showed up at the end of the list hidden off the screen unless you scrolled down.
To fix this problem in the Attributes section of the Navigation Controller in the Simulated Metrics I set Bottom Bar to Toolbar. I then did the same thing in the Table View Controller. I then added the Bar Button Items to the toolbar on the Table View Controller.
Then I had to control where the toolbar appeared downstream by calling
- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.toolbarHidden = YES;
}
in the applicable table view controllers and setting YES or NO.
For some reason I was unable to find good documentation for this process. It probably is out there, but I have included it here for others who may have this problem.

UITabBarController functionality with UITabBar

I'm making an app with interface builder using storyboarding.
I want to have a tab bar where no item is selected. This can be accomplished by setting
TabBar.SelectedItem = null;
But if you try to do that, you get the following error:
'Directly modifying a tab bar managed by a tab bar controller is not allowed.'
So I can't use the standard UITabBarController. I've created a custom UIViewController, and added a UITabBar. Switching between tabs is working fine, and having no selection is also working as it should.
But I have no idea how to show my other view controllers from my custom view controller with the tab bar. Remember that I'm using interfacebuilder, so I can't just create my view controllers in code as new objects and add them to the view. (as suggested in UITabBar funcionality without UITabBarController)
So how do I show my own views without using the UITabBarViewController?
Edit: Still haven't found a solution, but I did a hacky fix. Simple create an other tab bar and place it on top of the original tab bar. Listen to those events and use SelectedIndex to change the view displayed. Then add some function that will select / deselect the items on your own tab bar.
In fact, even if you design your others UIViewControllers from IB, you can instantiate them from code. You'll probably have to play a bit with frame and autoresizing properties to make them fit the part of your main view you want them to display inside, but it's possible.
So, knowing that, a simple solution is to create a simple UIView (we'll call it 'tabFrame') in your main UIViewController, which fill the screen from the top of your UITabBar to the top of the screen; instantiate the UIViewController corresponding to your tabs and add their view as subview of tabFrame. Now you just have to catch item selection from tabbar to hide or show the desired subviews.
Hope I'm clear enough, else don't hesitate to question!
EDIT: pointed out this morning that in storyboarding context, you can effectively instantiate viewControllers / scene from code, but for not loosing designer settings it must NOT be done through directly calling their constructors, but through StoryBoard.InstantiateViewController("vc_identifier") calls, after having set identifiers to VCs in storyboard editor.
See http://docs.xamarin.com/ios/recipes/General/Storyboard/Storyboard_a_TableView for example

Easy custom UITableView drawing

All,
I found the code in Matt Gallagher site ( http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html ) for this really neat design for a Table View... Im very new to Cocoa and Im having a hard time figuring out how to wire the darn thing in IB...
I loved the design and wanted to use something similar in a more complex structure... Nav Bar / Tab Bar with a few other views / TableView for the data in the first view... I found lots of tutorials to do that and got it working... When I tried to use that design in my project, things went crazy... in My MainWindow.xib I cant have a UIView where the arrow is pointing...
the nib looks like this:
Tab Bar Controller
Tab Bar
Nav Controller
Navigation Bar
Table View Controller
Table View
---->>>> (UIView for the backgroundImage )
Navigation Item
Tab Bar Item
UIView Controller
Tab Bar item
Window
can anyone guide me in the right direction??
Thanks !!!
It sounds like you're not having issues with the table view as much as the construction of the hierarchy around the table.
Instructions for creating the hierarchy would be as follows. I think you've diverged at around step 9:
Start with new copy of the default iPhone "View" template
Throw away the view controller class.
Open the MainWindow.xib and delete the view controller there too.
Find the controllers in the
Interface Builder library palette (they're
the yellow spheres at the top of the "Cocoa Touch" library in "Objects" mode whose icons contain
other objects).
Drag the tab view controller into
your MainWindow.xib file at the top
level.
Expand the tab view (triangle next to its name in the list view of the xib)
Drag a navigation controller into your expanded tab view (if this works, it should appear as one of the tabs along with the two view controllers that are there by default)
Expand the navigation controller
Drag a view controller (not a table view controller) into the navigation controller. It should appear as the content of the navigation controller.
Select the view controller (single click).
Press Command-4 (or select "Identity Inspector" from the "Tools" menu).
In the "Class Identity" popup menu, select EasyCustomTableController (this assumes that the current xib file is part of an Xcode project and this Xcode project already has EasyCustomTableController added to it).
Add a UIImageView to the view controller's view (this is your background image)
Add a UITableView to the view controller's view (this is your table). Add this view so it is after (and hence on top of) your image view.
There should be a tableView outlet on the view controller. Connect this to the table view.
Connect the app delegate's viewController to the tab bar controller (back in Xcode you can optionally change the type of this property to UITabViewController)
Should work.
The trick is that UITableViewController can't be used if you want the view to contain more than just a table. For this reason, you must use UIViewController and recreate the functionality that the UITableViewController adds. See here for how this is done:
http://cocoawithlove.com/2009/03/recreating-uitableviewcontroller-to.html
Thank you Matt (kind of cool that you answered)!!
I really appreciate the help... I've been messing around with it and got it to work using a UIViewController in another view (being created from the tableview)... Once I had the UITableViewController in the navigation I dropped the imageview & used a gray color; it looks great!! The initial screen has the rows big enough that scrolling is not an issue... I will go back and try to change that now...
I do have to say that IB is by far the most challenging step in app development for a newbie coming into Cocoa Touch !!! Yikes!

Combining UITabBarController with UINavigationContoller

I am sure this is very simple, yet I am stuck...
I have created an application and added UITabViewController (dragged in from the library in Interface Builder. My application has 3 different views, clicking on appropriate tab brings the different view. So far so good.
I want to convert one of the views to be a UINavigationController: basically a table with the option to delete rows (so UINavigationController would need to have a button "Edit" on top).
I saw many samples which would do either 1 or 2, but not both.
How would I combine it, keeping in mind that I have used provided UITabViewController and did not added UITabBar directly to the view.
Thanks
If you are using Interface Builder, you should be able to just drag and drop a navigation controller into your tab bar controller as a child controller. The next tab bar item should be generated for it automatically from that.
You can also do this programatically by just creating however many UINavigationControllers you need in an array and assigning that to the uitabbarcontroller appropriately.
I actually don't like this method of combining the UINavigationController and UITabBarController since the tab bar controller must always be visible, which can be really confusing sometimes.
Instead, I recommend you make your own custom UITabBarController (Tab bar controller inside a navigation controller, or sharing a navigation root view) which you add to the navigation controller. I personally don't know why Apple didn't do this; hopefully this is the standard way in 4.0 :)