TableView as subview with navigation controller - uitableview

I would like to have a view (one of five tabbars) with some subviews (labels, images and such) including a table view, so that the table view will only take up half of the screen (similar to this thread Add tableview as subview to view?). I have set up the views controller as tableview delegate and data source, but how can I use navigation with this table view (uinavigationcontroller)?
Clarification:
I started out with a tab bar based app, and wanted to have one of the tab bar views to have some labels in to top and a table view in the lower half of that view. I solved it myself, see below

This was of course simpler than I thought it was. I set up a tab bar controller with some tabs (with individual view controllers). I embedded one of the view controllers in a navigation controller (using the menu Editor -- Embed in -- Navigation Controller). Added the labels and a uitableview (through Storyboard) to the view and hooked up outlets for the labels and the table view, as well as setting the view controller as delegate and data source (UITableViewDelegate, UITableViewDataSource).

Related

Animation bug with always displayed large titles after popping view controller

I wanted to use the new Large Titles with largeTitleDisplayMode set to .always but got some strange animation issues while popping the pushed detail controller if the root UITableView's contentOffset.y is positive aka scrolled.
So this is how it should work:
And this is how it works after scrolling:
I guess it's a bug, but maybe anyone have a workaround till it's fixed?
To reproduce, create a new sample project, open Storyboard and do the following:
Add Navigation Controller and tick it's Navigation Bar's Prefers Large Titles value
Select it's Root View Controller and set it's Table View's Content to Static Cells.
Add many static cells or make then big enough, so your Table View become scrollable
Add a View Controller as detail view controller and setup the Show segues
Setup the Navigation Item's Large Titles property to Always for both view controller
Run the app, scroll to the bottom, perform a show/push segue and pop back

Navigation bar overlapping my content after show Segue

I have a view controller with a table view and a tab bar controller. I perform a segue when one of the cells is tapped in the didSelectRow method. I then pass the data in prepareForSegue. The segue is set up in the storyboard from the view controller to the tab bar and its kind is "Show".
When the tab bar controller is displayed (well, one of its view controllers), the content is at the very top of the view. The problem is fixed after I switch tab bars and then go back to the original tab bar. Any way to fix this?
Are you using interface builder?
Open storyboard where you defined this view controller.
Then in Attributes Inspector DESELECT the Extend Edges Under Top Bars property.
Alternatively you can make your view snap to the Top Layout Guide instead of the root view itself.

UITableViewContent Inset messed up on iOS 8

I have a navigation controller with a UITabBarController as the initial view controller. Within that, I have two UIViewController's as sub-viewcontrollers in the tab bar controller. Both of my view controllers have UITableView's in them. The first one always looks fine. However, the second view controller always has a messed up content inset. I don't know why because there doesn't seem to be any difference in the way I setup my table views. I can manually set the content inset in viewDidLoad, but there's got to be a better way since it's working by default in the first view controller.
This is the first table view. As you can see, the the content offset looks fine.
Something to note: when opaque navigation bars are turned off, the issue goes away.
This is the second table view. As you can see there is a table view cell underneath the navigation bar.
I fixed the issue by changing the structure of my view hierarchy. Apparently I should not of had a UINavigationController as the initial view controller, but rather had the UITabBarController as the initial view controller and from there have UINavigationControllers within the tab bar where needed.

Same UISearchBar for entire app?

I've seen a lot of apps that have a universal search bar that always remains at the top of the app. I have implemented a UISearchBar with a UITableView in one view controller. I want to have the same search bar on other view controllers in my app. How do I link these other UISearchBars to the one I have already created? I.e., how do I configure these other UISearchBars so that they return the same search results and link to the same UITableView?
Nested view controllers may be what you need.
Define a “top view controller” that manages a “top view” containing a search bar and add your (table) views to the top view (using -addSubview: on the top view) and the associated view controller(s) to the top view controller (using -addChildViewController: in the top VC and on itself).
In Interface Builder, you can define a top view and inside it a “container view.” The system then handles the insertion of the subview and sub-view controller.
By defining a good view controller hierarchy, you make your app design more logical and clean. I’d recommend to take some time into investigating a good hierarchy before diving into coding.
A final note: the UISearchDisplayController is an object (apparently not a view controller) that superimposes a search bar above a view controller’s view. You might be able to simply apply it immediately above the top-most view controller (the one that is always visible, like a navigation controller). It’s worth looking into it, if you didn’t already. ;-)
An example
View controller hierarchy
XYZTopViewController (managing a XYZTopView)
UINavigationController (managing a private navigation view hierarchy defined by Apple)
XYZFirstPageViewController (managing a XYZFirstPageView) (the “root” view controller)
XYZSecondPageViewController (managing a XYZSecondPageView) (pushed by nav. controller when you need it to)
View hierarchy
XYZTopView
UISearchBar
(private navigation view hierarchy defined by Apple)
XYZFirstPageView
(your view hierarchy belonging to the first page/screen)
Since you only every have one window per app, and view's don't have
levels, you have to make sure that view stays on top of the hierarchy,
no matter what. One relatively easy way is to add it directly to the
window above the rest of the interface (the navigation controller):
How to show a uiview alway on top?
In applicationDidLaunch:
// After the main navigation controller or tab controller has been added
// either programmatically or in the xib:
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,70,320,44)];
[self.window addSubview:searchBar];

How do you change a master view controller from UITableViewController to UIViewController in a storyboard

I was wondering if it is possible to change the master view controller in a split view controller from UITableView to UIViewController in a storyboard. I am looking for a way to make the master view contain regular non scrolling controls on the top and left sides with a scrollable table view talking up the rest of the view space.
Delete the table view controller (and the navigation controller if you want), drag out a UIView controller, and hook it up (control drag) either to the split view controller or the navigation controller, if you're using that.

Resources