How to add UIView over TableViewController

I would like to display a UIView over my table view, for testing purposes I used the search bar (to fix any possible problems with my code).

My setup:
Tablet controller
MyCustomTableViewController
View
TableView (to adjust cell height)
Searchbar

I positioned the search bar at the top of the “window” and pulled out a tabular view so that it was located directly below the search bar.
So everything looks great in IB.
But when I launch the application, tableview occupies the entire screen, and the search bar is not found anywhere.

I am new to developing an iPhone, so there might be a very simple solution (?).
/Jimmy

+4
source share
2 answers

Actually a simple solution:

  • Create your own subclass of UIViewController that implements UITableViewDelegate and UITableViewDataSource , as UITableViewController does. Also add UITableView output.
  • In the XIB file, put your search bar and UITableView in the view controller's view.
  • Connect table view to tableView output in custom UIViewController
  • Connect the delegate and UITableView data source to the file owner (your custom UIViewController that implements delegate rights)

You now have a custom view controller that works just like the UITableViewController , except that you have full control over its layout. You implement delegates in the same way.

+4
source

If you MyCustomTableViewController is actually a UITableViewController, then you will notice in IB that the “view” points directly to your UITableView instead of the root UIView in IB. This is the default behavior for UITableViewController objects. Just redirect the “view” to the root UIView, and everything should display correctly.

+1
source

Source: https://habr.com/ru/post/1301320/


All Articles