2016-06-10 78 views
1

Iam嘗試將tableview添加到視圖控制器。一切正常,但頁腳隱藏/禁用?我不知道。Tableview頁腳不顯示

我的代碼:

private let footerView = UIView() 
footerView.backgroundColor = UIColor.Green.color 
footerView.addSubview(activityIndicator) 
tableView.addSubview(footerView) 

tableView.delegate = self 
tableView.dataSource = self 
tableView.tableFooterView = footerView 
tableView.sectionFooterHeight = 20 
tableView.footerViewForSection(0) 
tableView.tableHeaderView = footerView 

肯定的:

func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? { 
    return "test.." 
} 

func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 
    return footerView 
} 

func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 
    return 20 
} 

我都嘗試執行(僅空格)分開並沒有什麼。

而我的頁腳視圖是淺灰色和實施活動的指標是「看不見」的(框被設置)

及其與的ViewController的tableView。

任何想法,爲什麼不頁腳視圖可見光右?

謝謝。

回答

4

你忘了把你的footerView


幀刪除代碼的所有第一部分,並使用此:

func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 
    return UIView(frame: CGRectMake(0, 0, tableView.bounds.size.width, 20)) 
} 

func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 
    return 20 
} 
1
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 

    let footerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 40)) 
    footerView.addSubview(activityIndicator) 
    return footerView 
} 
+0

儘管此代碼可能會回答這個問題,它會從一個解釋中受益。 – BDL

-1
addfooterView() 

func addfooterView() { 

footerView = UIView(frame: CGRectMake(0, 0, UIScreen 
.mainScreen().bounds.width, 150)) 
    footerView.backgroundColor = UIColor.whiteColor() 
    tableViewLFStation.tableFooterView = footerView } 

//調用此方法時您要在表格中添加頁腳視圖