2016-01-05 49 views
3

我正在使用UITableviewcontroller,我希望頁腳視圖始終停留在屏幕的底部。然而,頁腳視圖y位置正在根據tableviewcellheight更改。我怎樣才能始終堅持屏幕底部?如何讓footerview始終保持在UITableViewController的底部?

+0

使用tableFooterView屬性的表視圖 –

+0

重寫func tableView(tableView:UITableView,viewForFooterInSection部分: Int) - > UIView? { 如果部分== 1 { 讓footerView = UIView的(幀:CGRectMake(0,UIScreen.mainScreen()bounds.height - 40,tableView.frame.size.width,40)) 返回footerView } 返回UIView() } 這實際上是我的代碼塊。我想要在屏幕底部的頁腳,但它不會粘在屏幕的底部,並根據tableview的高度不斷變化 –

+0

編輯:=我不認爲這是可能的與uitableviewcontroller ..所以我所做的是添加視圖作爲導航控制器的子視圖,它爲我工作:) –

回答

-1

試試這個:

tableObj.tableFooterView = UIView(frame: CGRectMake(0, 0, 320, 150)) 
2

tableview頁腳視圖將永遠留在tableview的底部,總是與它滾動。如果您需要將頁腳視圖固定在底部,則不能使用TableViewController。您必須使用UIViewController,將tableView作爲子視圖。將頁腳也作爲另一個子視圖並完成。

+0

我知道這聽起來很愚蠢。但是可以在tableviewcontroller中添加另一個視圖嗎?這裏m工作在我必須使用tableviewcontroller的東西上,所以不能切換到視圖控制器。我試圖讓它工作:(是否有可能在tableviewcontroller類中添加任何其他視圖?也許讓它堅持到底部 –

+0

如果您使用的是'UINavigationController',您可以將'footerview'添加爲'subview '不要忘了從'viewDidDisappear'中刪除'footerView',否則它會出現在導航堆棧中的所有屏幕上。 – user1107173

-1

您可以在TableViewCell的底部添加一個UIView,這樣您的頁腳將始終保持在底部。

入住這LINK

+0

OP聲明「我希望頁腳視圖始終保持在屏幕底部「 –

+0

@EugeneBraginets是的,這就是上述鏈接的答案。 –

+0

@vivektakrani鏈接已損壞:( – Nathaniel

0

斯威夫特守則,使footerView填寫底部的休息空間, 那麼你可以使用自動佈局讓你在footerView底部查看:

override func viewDidLayoutSubviews() 
{ 
    super.viewDidLayoutSubviews() 


    guard let footerView = tableView.tableFooterView else 
    { 
     return 
    } 

    var cellsHeight:CGFloat = tableView.tableHeaderView?.frame.height ?? 0 

    let sections = self.numberOfSections(in: tableView) 
    for section in 0..<sections 
    { 

     let rows = self.tableView(tableView, numberOfRowsInSection: section) 

     for row in 0..<rows 
     { 
      let indexPath = IndexPath(item: row, section: section) 
      cellsHeight += self.tableView(tableView, heightForRowAt: indexPath) 
     } 
    } 

    var frame = footerView.frame 

    frame.size.height = tableView.contentSize.height - cellsHeight; 
    frame.origin.y = cellsHeight 

    footerView.frame = frame 
} 
相關問題