你的用來顯示更多數據的UITableView會出現這種情況嗎?比如tableView有多餘表格線,tableView表頭有空白區域,修改導航欄背景色和標題顏色、字體大小
一、你使用的表的類型是普通表:
UITableViewStylePlain
如果數據量比較少,而你的UITableView的高度是屏幕的高度,就會有很多沒用的表格線,這種情況下這樣就會沒有多餘表格線了
加上這句
_tableView.tableFooterView = [[UIViewalloc]initWithFrame:CGRectZero];
效果是這個樣子的
一、你使用的表的類型是分組表:
UITableViewStyleGrouped
有沒有出現過下面的這種情況發現上面有一段空白,加上這句就ok了
_tableView.tableHeaderView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,0,0.01)];
分段的tableView去掉段頭段位
_tableView.sectionFooterHeight = 0;
_tableView.sectionHeaderHeight = 0;
效果是這樣的:主要的問題倒是已經解決了,如果你需要的話繼續看下,如果你想分割線從界面頭開始,就要這樣寫
//分割線頂頭顯示
if ([_tableViewrespondsToSelector:@selector(setSeparatorInset:)]) {
[_tableViewsetSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
}
if ([_tableViewrespondsToSelector:@selector(setLayoutMargins:)]) {
[_tableViewsetLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cellrespondsToSelector:@selector(setSeparatorInset:)]) {
[cellsetSeparatorInset:UIEdgeInsetsZero];
}
if ([cellrespondsToSelector:@selector(setLayoutMargins:)]) {
[cellsetLayoutMargins:UIEdgeInsetsZero];
}
}
效果是這樣式的附加一點知識就是改變導航欄的屬性
//設置導航欄背景
[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"title.png"]forBarMetrics:UIBarMetricsDefault];
//設置導航欄字體屬性
NSDictionary *dict =@{NSForegroundColorAttributeName:[UIColorwhiteColor],NSFontAttributeName:[UIFontboldSystemFontOfSize:18]};
[self.navigationController.navigationBarsetTitleTextAttributes:dict];