iOS 8 UITableView插图:如果你有自定义布局的单元格,你可能也会遇到这个问题

Jor*_*ith 10 iphone ipad ios

在iOS 8上,对于较大的设备,默认的tableView inset似乎发生了变化.如果您正在布置自定义单元格并将其左侧布局约束与单元格的默认大小15插入匹配,则您的布局在较小的设备上看起来会很好,但在插入更改的较大设备上,您将获得类似于以下内容的内容:



TableViewCell分隔符插入对齐



我怎样才能解决这个问题?

Jor*_*ith 3

设法写了一些看起来效果很好的东西。如果有更好的解决方案,请分享。

@interface InsetRespectingTableViewCell()

@property (nonatomic) IBOutlet NSLayoutConstraint * leftContentInset;
@property (nonatomic) IBOutlet NSLayoutConstraint * rightContentInset;

@end

@implementation InsetRespectingTableViewCell


- (UITableView *)tableView {

    UIView *view;
    for (view = self.superview; ![view isKindOfClass:UITableView.class] && view; view = view.superview);
    return (UITableView *)view;

}

- (void)updateInset {

    CGFloat defaultInset = [self tableView].separatorInset.left;
    self.leftContentInset.constant = defaultInset;
    self.rightContentInset.constant = defaultInset;

}

- (void)didMoveToSuperview {

    [super didMoveToSuperview];
    [self updateInset];

}
Run Code Online (Sandbox Code Playgroud)

  • 有关正确的方法,请查看[这篇文章](http://stackoverflow.com/questions/27420888/uitableviewcell-with-autolayout-left-margin- Different-on-iphone-and-ipad) (2认同)