我在 Xcode 6 GM 上的 iPhone 6 Simulator (iOS 8) 的 UITableView
上发现了一个奇怪的空白区域。我试图从 Storyboard 和代码中设置 SeparatorInset
,但空白一直存在。
以下代码适用于 iOS 7 但不适用于 iOS 8(iPhone 6 模拟器)。
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
}
我在下面附上截图:
顺便说一下,我正在使用 AutoLayout。我希望有人能告诉我一种方法来删除 TableView
上奇怪的空白区域。
最佳答案
感谢学生用评论“试试这个 self.myTableView.layoutMargins = UIEdgeInsetsZero; 为我指明了正确的方向”这行代码仅适用于 iOS 8,因为 layoutMargins 仅适用于 iOS 8。如果我在 iOS 7 上运行相同的代码,它将崩溃。
@property(nonatomic) UIEdgeInsets layoutMargins Description The default spacing to use when laying out content in the view. Availability iOS (8.0 and later) Declared In UIView.h Reference UIView Class Reference
下面是通过将 tableview layoutMargins
和 cell layoutMargins
设置为 UIEdgeInsetsZero
(如果存在)来解决这个奇怪的空白的正确答案(对于iOS 8)。它也不会在 iOS 7 上崩溃。
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[tableView setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
请看下面的屏幕截图:-
关于ios - 为 Xcode 6 iPhone 模拟器移除 iOS 8 UITableView 上的 SeparatorInset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25762723/