删除iOS 8 UITableView for XCode 6 iPhone模拟器上的SeparatorInset [英] Remove SeparatorInset on iOS 8 UITableView for XCode 6 iPhone Simulator

查看:137
本文介绍了删除iOS 8 UITableView for XCode 6 iPhone模拟器上的SeparatorInset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XCode 6 GM上的 iPhone 6模拟器(iOS 8)的 UITableView 上发现了一个奇怪的空白区域。我试图从故事板和代码中设置 SeparatorInset ,但是白色空间就在那里。

I found a weird white space on UITableView for iPhone 6 Simulator (iOS 8) on XCode 6 GM. I have tried to set the SeparatorInset from both storyboard and also the code, but the white space is till there.

以下代码适用于iOS 7,但不适用于iOS 8(iPhone 6模拟器)。

The following code works on iOS 7 but not on iOS 8 (iPhone 6 simulator).

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }
}

我附上以下屏幕截图:

我顺便使用AutoLayout。我希望有人能告诉我一种方法来删除 TableView 上奇怪的空格。

I am using AutoLayout by the way. I hope someone can show me a way to remove the weird white space on the TableView.

推荐答案

感谢学生指出我正确的方向,注释试试这个self.myTableView.layoutMargins = UIEdgeInsetsZero ;这行代码仅适用于iOS 8,因为 layoutMargins 仅适用于iOS 8.如果我在iOS 7上运行相同的代码,它将崩溃。

Thanks Student for pointing me to the right direction with the comment "Try this self.myTableView.layoutMargins = UIEdgeInsetsZero;" This line of code will only work on iOS 8 because layoutMargins is only available from iOS 8. If I run the same code on iOS 7, it will crash.


@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来解决这个奇怪的空白区域的正确答案code> as UIEdgeInsetsZero 如果存在(适用于iOS 8)。它也不会在iOS 7上崩溃。

Below is the right answer to solve this weird white space by setting the tableview layoutMargins and cell layoutMargins as UIEdgeInsetsZero if it exists (for iOS 8). And it will not crash on iOS 7 as well.

-(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];
   }
}

请参阅下面的屏幕截图: -

See the screen shot below:-

这篇关于删除iOS 8 UITableView for XCode 6 iPhone模拟器上的SeparatorInset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆