Reputation: 325
I have a tableview in a tableview controller with a search bar. I want to add an image to the top of it in such a way, that it acts like a navigation bar and doesn't move and essentially shrinks the tableview. I usually use a view controller and add an image to the top, but I can't seem to do the tableviewcontroller. I tried adding a UIView and calling the
tableViewHeader
method, however my search controller disappears and when I scroll down in the tableview, the header disappears and the tableview covers the whole page.
Is there any way of adding sort of a sticky header to the tableview in the tableviewcontroller, so that it stays there and my search controller doesn't disappear.
Upvotes: 1
Views: 1610
Reputation: 1318
Add UIImgaeView
in HeaderView
of that TableView
.
Something like that -
let headerImageView = UIImageView.init(frame: Frame)
headerImageView.image = Image
self.tableView.tableHeaderView = headerImageView
Upvotes: 3
Reputation: 16446
No With UITableViewController
You can't add image like you can do with UIViewController
For now you have following options
1) Switch to UIViewController and add uitableview and whatever your view is.
2) If you are using navigation controller then add subview to navigation controlller's view
3) Add Subview directly to UIWindow
of appdelegate
Upvotes: 0