1

There are many questions like mine both in Objective-c and Swift that ask how to lock a UIToolbar to the top of a UITableViewController, and I will add to that list. However, my question is unanswered by the others. I need to lock it to the top of the view controller so that it is not considered a cell by the program, and so it doesn't move down, but is locked at the top instead.

All other answers that I found want me to either

(a) Embed the UITableViewController in a UINavigationViewController

or

(b) To use a UIViewController with a UITableView inside it


I do not want to do either one of these.
I want to keep a UITableViewController––not to replace it with a UIViewController and UITableView––and I do not want to use a UINavigationViewController––I am trying to not do that because it causes a plethora of issues in the rest of the app (which can be fixed but I don't want to have to do that).

rene
  • 41,474
  • 78
  • 114
  • 152
Daniel
  • 3,188
  • 14
  • 34
  • Surely your app has a few View controllers before you actually access this one right? – Saheb Roy Sep 05 '15 at 15:46
  • @SahebRoy - Yah. It does – Daniel Sep 05 '15 at 16:02
  • so it surely can have a navigation controller of the view controller is is coming from unless you specified not to show the nav controller from its parent VC – Saheb Roy Sep 05 '15 at 17:05
  • @SahebRoy - you are definitely correct, but I'm wondering if it is possible to do this a different way – Daniel Sep 05 '15 at 19:53
  • You can open it in a Model Segue and a false view or imageview at the top of the VC to make it appear that it the nav controller with a button at the left side with an action to pop the VC again. Or you can do it with Push segue as well – Saheb Roy Sep 06 '15 at 07:26
  • hey @Dopapp does this help? http://stackoverflow.com/questions/33480298/how-to-create-a-fixed-navigation-bar-ios-swift – Lukesivi Nov 19 '15 at 07:53

1 Answers1

0

What you are asking for is not reasonably possible. The root view of UITableViewController is a UIScrollView. Every view you add as a subview in a UITavleViewController must be part of that scrollview and thus will scroll with it.

To make it work you must take one of the options you mentioned (moving to a UIViewController with a table view as a subview is likely to cause the least disruption in your app).

There are a couple of unreasonable solutions I can think of: - implement the scrollviewDidScroll delegate method in you UITableViewController and constantly reposition tour toolbar within the scrollview to make it appear to always be at the top (the toolbar will probably jitter around and look terrible) - create a new UIWindow on top of your entire app that hold the toolbar (don't do this, it is a terrible idea).

alexkent
  • 1,556
  • 11
  • 25