ios - 为 Xcode 6 iPhone 模拟器移除 iOS 8 UITableView 上的 SeparatorInset

标签 ios iphone uitableview ios8 xcode6

我在 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];
    }
}

我在下面附上截图:

iPhone 6 Simulator weird white space on tableview

顺便说一下,我正在使用 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

enter image description here

下面是通过将 tableview layoutMarginscell 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];
   }
}

请看下面的屏幕截图:-

enter image description here

关于ios - 为 Xcode 6 iPhone 模拟器移除 iOS 8 UITableView 上的 SeparatorInset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25762723/

相关文章:

iOS11 以编程方式关闭 `safeAreaInsets`

ios - UITableView 部分边框

ios - objc_setAssociatedObject 函数错误在 64 位模式下不在 32 位

ios - 如何检索 Microsoft Band 1 上已有的应用程序磁贴列表

ios - 如何让对象对 Cocos2D 中的触摸使用react?

ios - 报亭应用程序的 Info.plist 必须包含 UINewsstandApp.error.message=true

iphone - iOS 核心数据对象的唯一标识符?

ios - 如何在IOS中查看网络是2G还是3G?

iphone - 完成 Issue + ios

ios - 如何知道 NSFetchedResultsChangeUpdate 的哪个属性被更改?