2014-08-27 50 views
3

我以編程方式創建tableviews和單元格。在iOS中移動8中的tableview細胞分離機,tableview cell separator in ios 8

enter image description here

即使我已經設置:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return kSomeNumber; 
} 

我的應用程序是ios7和我的手機是iOS8上。可能是什麼問題呢? 我不能使用cell.layoutMargins這是僅適用於ios8

+0

您能否解釋一下wha你的意思是「分離器移動」? – 2014-08-27 15:34:56

+0

嗨細胞高度是相同的,但分離器向上移動 – Ted 2014-08-27 15:42:31

回答

5

由於iOS8我們有layoutMargins這是導致你的線。

如果你有一個自定義單元格,添加此方法來刪除它:

- (UIEdgeInsets)layoutMargins 
{ 
    return UIEdgeInsetsZero; 
} 

或者在您添加此的UITableViewController:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ 

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { 
     [cell setLayoutMargins:UIEdgeInsetsZero]; 
    } 
} 

是必要的,以支持iOS7

的responsToSelector

另請參閱iOS 8 UITableView separator inset 0 not working瞭解更多信息

+0

謝謝!在我的自定義UITableViewCell類中只實現'-layoutMargins'並沒有訣竅(並且在iOS 7上工作正常) – 2014-12-02 21:36:45