If no Table View results, display “No Results” on screen

后端 未结 14 1607
挽巷
挽巷 2020-11-30 17:25

I have a tableview, where sometimes there might not be any results to list, so I would like to put something up that says \"no results\" if the

14条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 18:03

    For Xcode 8.3.2 - Swift 3.1

    Here is a not-so-well-known but incredibly easy way to achieve adding a "No Items" view to an empty table view that goes back to Xcode 7. I'll leave it to you control that logic that adds/removes the view to the table's background view, but here is the flow for and Xcode (8.3.2) storyboard:

    1. Select the scene in the Storyboard that has your table view.
    2. Drag an empty UIView to the "Scene Dock" of that scene

    1. Add a UILabel and any constraints to the new view and then create an IBOutlet for that view

    1. Assign that view to the tableView.backgroundView

    1. Behold the magic!

    Ultimately this works anytime you want to add a simple view to your view controller that you don't necessarily want to be displayed immediately, but that you also don't want to hand code.

提交回复
热议问题