
- (CGfloat)tableVIEw:(UItableVIEw *)tableVIEwheightForRowAtIndexPath:(NSIndexPath *)indexPath
如果我有一个单元格标识符的静态值,那么单元格内图像的高度不能动态变化.
那么我是否需要为每个细胞设置不同的细胞标识符值?还有其他方法吗?
我不能使用除tablevIEw之外的其他视图,因为我需要根据用户交互动态显示一些单元格.
谢谢.
解决方法 您应该引用数据模型以获取图像大小并返回行高.-(CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForRowAtIndexPath:(NSIndexPath *)indexPath { UIImage *image = dataModel[indexPath.row]; return image.size.height + 16.0; //16 is for padding} 如果您对单元格进行子类化,则可以在-layoutsubvIEws中调整imageVIEw框架(超级之后):
- (voID)setupImageVIEw{ UIImageVIEw *imageVIEw = [[UIImageVIEw alloc] initWithFrame:CGRectZero]; imageVIEw.contentMode = UIVIEwContentModeScaleAspectFit; imageVIEw.clipsToBounds = YES; self.contentimageVIEw = imageVIEw; [self.contentVIEw addSubvIEw:imageVIEw];}- (voID)layoutSubvIEws{ [super layoutSubvIEws]; CGRect bounds = self.contentVIEw.bounds; float margin = 8.0; CGRect textVIEwFrame = CGRectZero; textVIEwFrame = CGRectMake(margin,roundf(margin * 2.0),bounds.size.wIDth - (margin * 2.0),roundf(bounds.size.height - (margin * 4.0))); self.contentimageVIEw.frame = textVIEwFrame;} 总结 以上是内存溢出为你收集整理的ios TableView不同的单元格高度全部内容,希望文章能够帮你解决ios TableView不同的单元格高度所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)