Search code examples
iosuitableviewswift3uiimageviewuisearchcontroller

How to add an image above tableview in TableViewController - Swift 3


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.


Solution

  • Add UIImgaeView in HeaderView of that TableView. Something like that -

        let headerImageView = UIImageView.init(frame: Frame)
    
        headerImageView.image = Image
    
        self.tableView.tableHeaderView = headerImageView