IOS8-tableViewSeparatorInsetZero

独奏

技术分享|2015-6-27|最后更新: 2023-2-23|
type
Post
status
Published
date
Jun 27, 2015
slug
summary
tags
category
技术分享
icon
password
iOS7 中用以下方法可使UITableView cell lines靠左
self.tableview.separatorInset = UIEdgeInsetsZero;
但在 iOS8 中该办法已失灵啦
经过翻阅 iOS8 文档发现用以下两种办法即可解决该问题
方法一:
- (void) viewDidLoad { [...] self.tableView.separatorInset = UIEdgeInsetsZero; if ([self.tableView respondsToSelector:@selector(layoutMargins)]) { self.tableView.layoutMargins = UIEdgeInsetsZero; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { [...] cell.separatorInset = UIEdgeInsetsZero; if ([cell respondsToSelector:@selector(layoutMargins)]) { cell.layoutMargins = UIEdgeInsetsZero; } }
方法二:
UITableViewCell 重写下面方法
- (UIEdgeInsets)layoutMargins{ return UIEdgeInsetsZero; }