节中的行数为1; 索引路径中行的高度为:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return [LZHThreadsNoticeTableViewCell cellHeightForThreadsNotice:_myThreadsDataArray[tag-1][indexPath.row]];
}
高度约为95.0f; 我定制了UITableViewCell
LZHThreadsNoticeTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:reusableCellWithIdentifier];
if (cell==nil) {
cell=[[LZHThreadsNoticeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reusableCellWithIdentifier];
}
[cell configureThreadsNotice:_myThreadsDataArray[tag-1][indexPath.row]];
return cell;
分离线位于细胞的中心
按下单元格时如下所示:
那么为什么分隔线显示在错误的位置?谢谢。
布局子视图方法如下:
-(void)layoutSubviews{
[_postTimeLabel sizeToFit];
_postTimeLabel.frame=CGRectMake(_viewWidth-_postTimeLabel.frame.size.width-LZHThreadsNoticeDistanceBetweenViews, LZHThreadsNoticeDistanceBetweenViews, _postTimeLabel.frame.size.width, _postTimeLabel.frame.size.height);
CGSize opticalTitleLableSize=[_titleLabel sizeThatFits:CGSizeMake(_viewWidth-3*LZHThreadsNoticeDistanceBetweenViews-_postTimeLabel.frame.size.width, 9999)];
_titleLabel.frame=CGRectMake(LZHThreadsNoticeDistanceBetweenViews, LZHThreadsNoticeDistanceBetweenViews, opticalTitleLableSize.width, opticalTitleLableSize.height);
CGSize opticalMyReplyLableSize=[_myReplyLabel sizeThatFits:CGSizeMake(_viewWidth-2*LZHThreadsNoticeDistanceBetweenViews, 9999)];
_myReplyLabel.frame=CGRectMake(LZHThreadsNoticeDistanceBetweenViews, _titleLabel.frame.origin.y+_titleLabel.frame.size.height+LZHThreadsNoticeDistanceBetweenViews,opticalMyReplyLableSize.width, opticalMyReplyLableSize.height);
CGSize opticalNoticeLabelSize=[_noticeLabel sizeThatFits:CGSizeMake(_viewWidth-2*LZHThreadsNoticeDistanceBetweenViews, 9999)];
_noticeLabel.frame=CGRectMake(LZHThreadsNoticeDistanceBetweenViews, _myReplyLabel.frame.origin.y+_myReplyLabel.frame.size.height+LZHThreadsNoticeDistanceBetweenViews, opticalNoticeLabelSize.width, opticalNoticeLabelSize.height);
_seperatorLabel.backgroundColor=LZHThreadsNoticeSeperatorColor;
_seperatorLabel.frame=CGRectMake(LZHThreadsNoticeDistanceBetweenViews, _noticeLabel.frame.origin.y+_noticeLabel.frame.size.height+LZHThreadsNoticeDistanceBetweenViews, _viewWidth-LZHThreadsNoticeDistanceBetweenViews, 1.0f);
}
我有五个标签,从上到下。 细胞高度方法是:
+(CGFloat)cellHeightForThreadsNotice:(LZHThreadsNotice *)threadsNotice{
CGFloat viewWidth=[[UIScreen mainScreen]bounds].size.width;
UILabel *noticeLabel=[[UILabel alloc]init];
noticeLabel.font=[UIFont systemFontOfSize:LZHThreadsNoticeSmallFontSize];
if (threadsNotice.noticeType==LZHTHreadsNoticeTypeReply) {
noticeLabel.text=[NSString stringWithFormat:@"%@答复您说:%@",threadsNotice.user.userName,threadsNotice.noticeContext];
}else{
noticeLabel.text=[NSString stringWithFormat:@"%@引用您说:%@",threadsNotice.user.userName,threadsNotice.noticeContext];
}
noticeLabel.numberOfLines=0;
noticeLabel.lineBreakMode=NSLineBreakByCharWrapping;
noticeLabel.font=[UIFont systemFontOfSize:LZHThreadsNoticeSmallFontSize];
CGSize opticalNoticContextLableSize=[noticeLabel sizeThatFits:CGSizeMake(viewWidth-2*LZHThreadsNoticeDistanceBetweenViews, 9999)];
UILabel *titleLabel=[[UILabel alloc]init];
titleLabel.text=threadsNotice.title;
titleLabel.numberOfLines=0;
titleLabel.lineBreakMode=NSLineBreakByCharWrapping;
titleLabel.font=[UIFont boldSystemFontOfSize:LZHThreadsNoticeBigFontSize];
UILabel *postTimeLabel=[[UILabel alloc]init];
postTimeLabel.font=[UIFont systemFontOfSize:LZHThreadsNoticeSmallFontSize];
postTimeLabel.text=threadsNotice.postTime;
[postTimeLabel sizeToFit];
CGSize opticalTitleLableSize=[titleLabel sizeThatFits:CGSizeMake(viewWidth-postTimeLabel.frame.size.width-3*LZHThreadsNoticeDistanceBetweenViews, 9999)];
UILabel *myReplyContextLabel=[[UILabel alloc]init];
myReplyContextLabel.text=[NSString stringWithFormat:@"您的帖子:%@",threadsNotice.myReplyContext];
myReplyContextLabel.numberOfLines=0;
myReplyContextLabel.lineBreakMode=NSLineBreakByCharWrapping;
myReplyContextLabel.font=[UIFont systemFontOfSize:LZHThreadsNoticeSmallFontSize];
CGSize opticalMyReplyContextLabelSize=[myReplyContextLabel sizeThatFits:CGSizeMake(viewWidth-2*LZHThreadsNoticeDistanceBetweenViews, 9999)];
return 4*LZHThreadsNoticeDistanceBetweenViews+opticalTitleLableSize.height+opticalNoticContextLableSize.height+opticalMyReplyContextLabelSize.height+1.0f;
}