2015-04-27 43 views
2

我有動態UITableView。當行數不足以填充屏幕時,我將以編程方式繪製UIView並將其設置爲self.tableView.tableFooterView。空行有圖像(紅線)。 我需要知道尺寸x(見圖)知道需要繪製多少行。我怎麼才能得到它?如何獲取tableView和tabBar之間的大小?

enter image description here

回答

1

你可以得到contentSize,做從表視圖的幀大小的差異。因此,例如:

let space = tableView.frame.height - tableView.contentSize.height 

如果有比的tableView的高度更多的內容(如果它滾動)這個值將是負的,而在這種情況下,剛剛以0

也是因爲這個來代替它你已經必須添加單元格並致電reloadData()

其他選項可以將行數乘以tableView.rowHeight(如果它是固定的),或者對每行調用tableView:heightForRowAtIndexPath:並將它們加在一起。

0

嘗試

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 

    CGSize statusBarSize = [UIApplication sharedApplication].statusBarFrame.size; 
    CGSize navigationBarSize = self.navigationController.navigationBar.frame.size; 
    CGSize tableViewContentSize = self.tableView.contentSize; 
    CGSize tabBarSize = self.tabBarController.tabBar.frame.size; 

    UIView *tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, tableViewContentSize.width, self.tableView.frame.size.height - statusBarSize.height - navigationBarSize.height - tableViewContentSize.height - tabBarSize.height)]; 
    tableFooterView.backgroundColor = [UIColor redColor]; 
    self.tableView.tableFooterView = tableFooterView; 
} 
相關問題