tableView.reloadData()没有调用heightForHeaderInSection?

时间:2016-06-28 18:41:07

标签: swift uitableview height xcode7 uiinterfaceorientation

我有一个tableView,其中各个部分的标题具有不同的高度。当方向改变时,我想更新标题的高度。

但我注意到调用tableView.reloadData()不会影响方法heightForHeaderInSection。

如何更改方向更改时的标题高度?

P.S 委托已设置。

heightForHeaderInSection:

override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {

    if(section == 1) { return screenHeight - 300 }
    else { return 0 }

}

willRotateToInterfaceOrientation:

override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {

    if(toInterfaceOrientation.isLandscape)
    {
        if(wasInPortrait){ screenHeight = bounds.width }
        else { screenHeight = bounds.height }
    }
    else
    {
        if(wasInPortrait){ screenHeight = bounds.height }
        else { screenHeight = bounds.width }
    }

    self.tableView!.reloadData()

}

viewDidLoad中:

let bounds = UIScreen.mainScreen().bounds
var screenHeight: CGFloat!
var wasInPortrait = true

override func viewDidLoad() 
{
   super.viewDidLoad()

   screenHeight = bounds.height

   if UIApplication.sharedApplication().statusBarOrientation.isLandscape { wasInPortrait = false }

   dispatch_async(dispatch_get_main_queue()) { self.rateMe() }

}

0 个答案:

没有答案
相关问题