0

當試圖添加表涵蓋視圖控制器的整個視圖像這樣:添加表導航控制器視圖編程不工作

func setConstraints(){ 

    self.view.addSubview(statisticsTable); 

    statisticsTable.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true; 
    statisticsTable.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true; 
    statisticsTable.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true; 
    statisticsTable.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true; 
} 

表犯規顯示。我是否正確地假設,通過導航控制器中的topAnchor,我們指的是視圖控制器視圖的頂部(這是導航欄結束的位置?)。這看起來很簡單,所以我很明顯在這裏明顯地忽略了某些東西謝謝。

回答

1

,只要您在代碼中創建一個視圖,並試圖限制添加到視圖你必須記住設置translatesAutoresizingMaskIntoConstraints

func setConstraints(){ 

    self.view.addSubview(statisticsTable); 
    // try to add this before you add your constraints to the view 
    statisticsTable.translatesAutoresizingMaskIntoConstraints = false 

    statisticsTable.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true; 
    statisticsTable.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true; 
    statisticsTable.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true; 
    statisticsTable.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true; 
} 
當然
+0

....我知道我缺少明顯。對不起,謝謝 –

+0

歡迎。看看它是否有效,所以你可以檢查問題,以便它可以幫助其他人。 –

相關問題