好的,我不知道iOS 8的用途,但是当我在其上运行我的应用程序时,我会看到这些额外的UITableViewSeparatorViews:
我使用了Xcode 6 View Debugger,我看到在这个有问题的UITableView中,我看到这些额外的视图被添加为我的UITableViewCellContentView的子视图
_UITableViewCellSeparatorView
为什么iOS 8会将这些随机子视图添加到我的手机内容中?
从屏幕截图中可以看出,那些额外的行是没有到达屏幕边缘的行。
在我的视图控制器中,我使用以下代码使线条一直到屏幕边缘:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[tableView setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
在我的自定义单元格类中,我正在设置:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
_reuseID = reuseIdentifier;
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.contentView.backgroundColor = [[BSGThemeManager sharedTheme] clearColor];
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.containerView = [[UIView alloc] init];
_photo = [[BSGUserPhotoView alloc] init];
[_photo clipPhotoToRadius:37.5];
//_photo.layer.cornerRadius = 37.5 / 2.0;
//_photo.layer.borderColor = [[BSGThemeManager sharedTheme] photoBorderColor];
//_photo.layer.borderWidth = [[BSGThemeManager sharedTheme] photoBorderWidth];
//_photo.clipsToBounds = YES;
self.photo.alpha = 0;
_message = [[UILabel alloc] init];
_message.backgroundColor = [[BSGThemeManager sharedTheme] clearColor];
_message.numberOfLines = 0;
_message.lineBreakMode = NSLineBreakByWordWrapping;
_message.font = [[BSGThemeManager sharedTheme] varelaRoundFontWithSize:15];
self.message.alpha = 0;
_time = [[UILabel alloc] init];
_time.textAlignment = NSTextAlignmentRight;
_time.font = [[BSGThemeManager sharedTheme] helveticaNeueFontWithSize:16];
_time.textColor = [[BSGThemeManager sharedTheme] postTimeColor];
[_time setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[_time setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
self.time.alpha = 0;
[self.containerView addSubview:_photo];
[self.containerView addSubview:_message];
[self.containerView addSubview:_time];
[self.contentView addSubview:self.containerView];
[self addAllConstraints];
}
return self;
}
我不确定这条线是否是原因:
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
我的手机的Autolayout代码是:
-(void)addAllConstraints
{
self.containerView.translatesAutoresizingMaskIntoConstraints = NO;
self.photo.translatesAutoresizingMaskIntoConstraints = NO;
self.message.translatesAutoresizingMaskIntoConstraints = NO;
self.time.translatesAutoresizingMaskIntoConstraints = NO;
id views = @{
@"containerView": self.containerView,
@"photo": self.photo,
@"message": self.message,
@"time": self.time
};
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[containerView]|" options:0 metrics:nil views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[containerView]|" options:0 metrics:nil views:views]];
// --------------------------------------------------
// Horizontal Constraints
// --------------------------------------------------
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[photo(37.5)]-15-[message(195)]" options:0 metrics:nil views:views]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[time]-10-|" options:0 metrics:nil views:views]];
// --------------------------------------------------
// Vertical Constraints
// --------------------------------------------------
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[photo(37.5)]" options:0 metrics:nil views:views]];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.photo attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0]];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.message attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.photo attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0]];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.time attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.photo attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0]];
}
其他人遇到过这个奇怪的iOS 8错误?
它不会出现在iOS 7上。
答案 0 :(得分:2)
我找到了一个简单的解决方案,当我覆盖layoutSubviews
方法时,我也称之为超级方法,如下所示:
-(void)layoutSubviews {
[super layoutSubviews];
// rest of custom implementation code here
. . .
}
希望有所帮助
答案 1 :(得分:0)
将突出显示更改为' 0'然后它解决了。这是通过XIB。
答案 2 :(得分:0)
我的一个子视图被称为“消息”,它只是一个UILabel。
在我的自定义tableview单元格的类中,此代码导致出现额外的行:
-(void)layoutSubviews
{
self.message.preferredMaxLayoutWidth = self.bounds.size.width * 0.75;
}
在摆脱它之后,细胞在iOS 7中表现得像我喜欢它。
答案 3 :(得分:0)
对我来说,自定义tableViewCells的动态高度导致了一个问题,特别是heightForRowAtIndexPath
和estimatedHeightForRowAtIndexPath
委托方法。一个适用于iOS 7,另一个适用于iOS 8.通过有条件地检查iOS版本来解决它。