我发现了一个奇怪的空白UITableView
for iPhone 6 模拟器(iOS 8) 在 Xcode 6 GM 上。我尝试过设置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];
}
}
我在下面附上了屏幕截图:
顺便说一句,我正在使用自动布局。我希望有人能告诉我一种方法来消除奇怪的空白TableView
.
感谢学生通过评论为我指明了正确的方向“试试这个 self.myTableView.layoutMargins = UIEdgeInsetsZero;" 这行代码仅适用于 iOS 8,因为布局边距仅适用于 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
and cell layoutMargins
as 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];
}
}
请参阅下面的屏幕截图:-
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)