我有一个UITableViewCell
的子类,使用Masonry设置约束取决于我的单元格样式(枚举)。例如,我有一个带有一些按钮的正确包装器,有时我想在我的包装器的宽度不等于零时使用我的UITextView
的排除路径。只有在我向下滚动到此单元格并再次向上和向下滚动后,所有工作才有效。在第一次尝试时我有
我向上和向下滚动后
- (void)setCellType:(ReservationCellType)cellType
{
self->_cellType = cellType;
CGFloat rightButtonsWrapperWidth = 0;
CGFloat rightButtonsWrapperHeight = 0;
if (cellType == ReservationCellTypeSeating) {
if (self.reservationStatus == ReservationStatusArrived) {
rightButtonsWrapperWidth = 100.f;
rightButtonsWrapperHeight = 100.f;
} else {
rightButtonsWrapperWidth = 0;
rightButtonsWrapperHeight = 0;
}
}
[self.rightButtonsWrapper mas_remakeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(rightButtonsWrapperWidth);
make.height.mas_equalTo(rightButtonsWrapperHeight);
}];
if (cellType == ReservationCellTypeSeating) {
if (self.reservationStatus == ReservationStatusArrived) {
[self addRightButtonsWrapperExcludedPathWidth:rightButtonsWrapperWidth height:rightButtonsWrapperHeight];
}
}
}
addRightButtonsWrapperExcludedPathWidth:height:
- (void)addRightButtonsWrapperExcludedPathWidth:(CGFloat)width height:(CGFloat)height
{
CGRect frame = CGRectMake(CGRectGetMinX(self.rightButtonsWrapper.frame), CGRectGetMinY(self.rightButtonsWrapper.frame), width, height);
CGRect rightWrapperExclusionRect = [self.noteTextView convertRect:frame fromView:self.wrapper];
UIBezierPath *rightWrapperExcludedPath = [UIBezierPath bezierPathWithRect:rightWrapperExclusionRect];
self.noteTextView.textContainer.exclusionPaths = @[rightWrapperExcludedPath];
[self.wrapper layoutIfNeeded];
}
在cellForRowAtIndexPath:
我致电[cell layoutIfNeeded]
;请帮帮我。第二个问题是 - 在调用reloadData之前,我的计算总是错误的。经过一些滚动,我遇到了很多布局问题。求你帮帮我。