gsdios / SDAutoLayout

One line of code to implement automatic layout. 一行代码搞定自动布局!支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于做最简单易用的AutoLayout库。The most easy way for autoLayout. Based on runtime.
MIT License
5.9k stars 1.28k forks source link

cell自动布局失效并且自动获取高度返回为0 #279

Closed SunsgneDZ closed 6 years ago

SunsgneDZ commented 6 years ago

[tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[CommentTextCell class] contentViewWidth:kScreenWidth]; 上面的这个方法输出值为0 ...并且 cell上所有视图的起始坐标都变成(0,0)...

神奇的事,开始写好是ok的,然后..写完其他模块的时候回来检查,发现这里的布局都没用了。 排查不出是什么原因造成的了,故来请教T T....

请问会是什么原因导致的呢?

无奈... 谢谢...

SunsgneDZ commented 6 years ago

部分代码...

//cell.m //auto-layout CGFloat padding = 10.f;

self.personImg.sd_layout.leftSpaceToView(self.contentView, padding).topSpaceToView(self.contentView, padding).widthIs(40).heightEqualToWidth();
self.personNameLabel.sd_layout.leftSpaceToView(self.personImg, padding).topEqualToView(self.personImg).widthIs(200).heightIs(20);
self.scoreImg.sd_layout.leftEqualToView(self.personNameLabel).topSpaceToView(self.personNameLabel, padding/2).widthIs(70).heightIs(10);
self.timeLabel.sd_layout.rightSpaceToView(self.contentView, padding).topEqualToView(self.personNameLabel).leftSpaceToView(self.scoreImg, padding).heightIs(20);
self.messageLabel.sd_layout.leftEqualToView(self.personNameLabel).rightSpaceToView(self.contentView, 2*padding).topSpaceToView(self.personNameLabel, 2*padding).autoHeightRatio(0);

[self setupAutoHeightWithBottomView:self.messageLabel bottomMargin:padding];

//vc.m return [tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[CommentTextCell class] contentViewWidth:kScreenWidth];

代码应该是没问题的(应该T T),毕竟开始是好的

SunsgneDZ commented 6 years ago

而且我把这部分代码分离出来,新建了一个工程,发现 自动布局、返回高度 完全是没问题的...

Jeykit commented 6 years ago

有兴趣可以了解一下MUKit这个框架MUTavleViewManager或许可以解决你的问题。地址https://github.com/Jeykit/MUKit

发自我的 iPhone

在 2018年5月25日,下午2:49,Dz notifications@github.com<mailto:notifications@github.com> 写道:

而且我把这部分代码分离出来,新建了一个工程,发现 自动布局、返回高度 完全是没问题的...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/gsdios/SDAutoLayout/issues/279#issuecomment-391958746, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIoJ90zywwBxm6Ip3cOsifwjIy-WFhkSks5t16lfgaJpZM4UNcyz.

gsdios commented 6 years ago

@SunsgneDZ 是全部布局都无效了吗?是否中间引入了其他第三方库?可以检查下是否有人在重写UIView子类+load方法时候违规调用了[super load],有的话把这个super调用注释掉,根本不需要也不能在load方法里面调用super方法的

SunsgneDZ commented 6 years ago

嗯,都失效了,中间是有引入过其他库,但是有点难排查是哪个(加入有点多)。 好的,我去检查下其他库,那问题应该是其他库重写了部分方法导致的?

gsdios commented 6 years ago

@SunsgneDZ 就全局搜+ (void)load 方法就可以找到了

SunsgneDZ commented 6 years ago

@gsdios 果然是这个问题,我有个新加的类别调用了[super load] 这个方法,注释后好了...万分感谢!!!!!!!!!