dzenbot / DZNEmptyDataSet

A drop-in UITableView/UICollectionView superclass category for showing empty datasets whenever the view has no content to display
https://www.cocoacontrols.com/controls/dznemptydataset
MIT License
12.09k stars 1.73k forks source link

tableView.tableHeaderView returning ni #251

Open mhlangagc opened 8 years ago

mhlangagc commented 8 years ago

I have a tableHeaderView in my UITableViewController that displays some data pulled from Parse. On trying to used this function I get a nil value returned and a crash. Removing it allows the app to run without crashing but does not show the background view setup when the cells are empty. Anything I could be missing?

func verticalOffsetForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat {

        return -tableView.tableHeaderView!.frame.size.height/2.0

}
dzenbot commented 8 years ago

Well, you should not force unwrap. Use a let guard or if let and the exception should go away. Maybe this callback es called to early, before your tableHeaderView is initialised. Try that out first.

sugitatestblue commented 2 years ago

-tableView.tableHeaderView!.frame.size.height/2.0 is fit to top tableView?