在beginupdate和endupdate时,iOS 8中的Rect UITableViewCell

时间:2014-12-18 02:22:07

标签: ios objective-c iphone ios8

我正在构建一个带有样式tableview Grouped的UITableView,并在方法框UITableViewCell上给出一个间隙(左边距)

- (void)setFrame:(CGRect)frame {

    if(IOS_7){ //above ios 6
     CGFloat gap = 10.0f;

     frame.origin.x += gap;
     frame.size.width -= gap*2;
    }
    [super setFrame:frame];
}

result like this

然后在5s后,我做了调用方法

[_table beginUpdates];
[_table endUpdates];

结果like this

右边的差距是我的差距的两倍=(差距* 2)

此问题仅适用于ios 8,

在uitableviewcell中是iOS 8调用两次setFrame吗? 以及如何解决它?

请注意: - 我已尝试使用CGRectMake(0.0f, frame.origin.y, [UIScreen mainScreen].bounds.size.width, frame.size.height);重置帧,但如果我使用ipad与左侧菜单一侧,它不能解决我的问题, - 不使用自定义单元格(仅使用默认的uitableviewcell)

1 个答案:

答案 0 :(得分:0)

您正在设置错误的帧。你应该这样做:

- (void)setFrame:(CGRect)frame {

    if(IOS_7){ //above ios 6
     CGFloat gap = 10.0f;

     frame.origin.x += gap;
     frame.size.width -= gap*2;
     [super setFrame: frame];
    }

}