删除 iOS 8 UITableView 上的 SeparatorInset for Xcode 6 iPhone Simulator [英] Remove SeparatorInset on iOS 8 UITableView for Xcode 6 iPhone Simulator

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

问题描述

我在 Xcode 6 GM 上的 iPhone 6 Simulator (iOS 8) 的 UITableView 上发现了一个奇怪的空白.我试图从故事板和代码中设置 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 上奇怪的空白.

解决方案

感谢学生用评论Try this self.myTableView.layoutMargins = UIEdgeInsetsZero;"为我指出正确的方向这行代码仅适用于 iOS 8,因为 layoutMargins 仅适用于 iOS 8.如果我在 iOS 7 上运行相同的代码,它会崩溃.

<块引用>

@property(nonatomic) UIEdgeInsets layoutMargins描述 在视图中布置内容时使用的默认间距.可用性 iOS(8.0 及更高版本)在 UIView.h 中声明参考 UIView 类参考

下面是通过将 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:)]) {[单元格 setLayoutMargins:UIEdgeInsetsZero];}}

请看下面的屏幕截图:-

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.

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

I attached screenshot below:

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

解决方案

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

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 上的 SeparatorInset for Xcode 6 iPhone Simulator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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