2016-12-15 66 views
2

我有一個的tableView具有:夫特如何移動的tableView backGroundView標籤

1-)第1頭

TableView Cell 

2-)第2頭

Tableview Cell 

3-)第3部分

(n rows that contains list of records) 

我的tableView有3個 部分。在第3節我列出了記錄。當沒有記錄時,我會顯示一個標籤,顯示「沒有記錄」我的表格視圖,如下圖所示。

My Table View Picture

但我的問題是,我想移動標籤到的tableview的底部(在「+」視圖)我如何才能將這個標籤。這是我的SWIFT代碼

func setNoDataInfoIfAbsenceNotExists() 
{ 
    let noDataLabel : UILabel = UILabel() 
    noDataLabel.frame = CGRectMake(0, 0 , (self.tableView.bounds.width), (self.tableView.bounds.height)) 
    noDataLabel.text = "No Records Found" 
    noDataLabel.textColor = UIColor.blackColor() 
    noDataLabel.textAlignment = .Center 
    self.tableView.backgroundView = noDataLabel 
    self.tableView.separatorStyle = .None 
} 
+0

你爲什麼不使用故事板來代替,而改變約束??? –

+0

你在「+」視圖上的含義是什麼?你的意思是使標籤子視圖的+視圖或點擊+你想移動標籤??? –

+0

nodataLabel.frame =(+查看).frame試試這個... –

回答

1

添加此行

tableView.tableFooterView = tableViewFooter 

你有導致這樣。請參閱文本視圖 底部的藍色視圖。

你的觀點只是堅持你的tableview高度,你總是在tableview的結尾看到你的觀點。

enter image description here

+0

是的,這是我的工作。謝謝! – OmerArslan

2

你讓框架noDataLabel是表視圖和文字的大小是在這個框架中心。

您應該嘗試使框架變小(嘗試CGRectMake(0,0,0,0)並在設置文本後調用noDataLabel.sizeToFit()),然後使用noDataLabel.center.xnoDataLabel.center.y進行定位。

嘗試:

noDataLabel.text = "No Records Found" 
noDataLabel.sizeToFit() 
noDataLabel.center.x = tableView.center.x 
noDataLabel.center.y = tableView.frame.height - noDataLabel.frame.height 
+0

noDataLabel.text = 「沒有找到記錄」 noDataLabel.sizeToFit() noDataLabel.center.x = tableView.center.x noDataLabel.center.y = tableView.frame.height -noDataLabel.frame.height我添加這行,但標籤仍然在同一位置 – OmerArslan

+0

你試過了:noDataLabel.frame = CGRectMake(0,0,0,0)? –

+0

let noDataLabel:UILabel = UILabel() noDataLabel。frame = CGRectMake(0,0,0,0) noDataLabel.text =「沒有找到記錄」 noDataLabel.sizeToFit() noDataLabel.center.x = tableView.center.x noDataLabel.center.y = tableView.frame .height - noDataLabel.frame.height是的,我嘗試 – OmerArslan

0

新建小區將包含文本「無結果」標籤(或任何你需要的)。 在你的代碼:

numberOfRowsInSection

//other part of your implementation 
if indexPath.section == 3 { 
    return dataArray.isEmpty ? 1 : dataArray.count 
} 

cellForRowAtIndexPath方法:

// other part of your implementation 
if indexPath.section == 3 { 
    guard !dataArray.isEmpty else { 
     return NoDataCell() // replace with your implementation 
    }   return YourDataCell() 
} 
+0

但是在這種情況下,「無數據單元」將是可選的並且像單元一樣工作。我認爲使用單元格作爲頁腳是一個更好的主意。不是嗎? – OmerArslan