简体   繁体   English

iOS实现了长滚动视图的最佳实践

[英]iOS implement a long scroll view best practice

Hi i would to implement a very long scroll view for a forum-like view, designing something similar to this image 嗨,我想为一个类似于论坛的视图实现一个非常长的滚动视图,设计类似于这个图像的东西

would it possible to implement this with a table view (considering the not very defined borders between cells and some views overlapping other cells) or i should write a long scroll view with many subviews (memory management?)? 是否可以用表格视图实现这一点(考虑到单元格之间没有非常明确的边界和一些与其他单元格重叠的视图)或者我应该编写一个包含许多子视图的长滚动视图(内存管理?)? Thanks 谢谢

Use UITableView , and it would be better if you subclass UITableViewCell and use the layoutSubviews method to adjust the subviews when you adjust the size of the cell. 使用UITableView ,如果你UITableViewCell并使用layoutSubviews方法在调整单元格大小时调整子视图会更好。 Change the cell size according to the content present in it. 根据其中的内容更改单元格大小。

Check the below links for this: 请查看以下链接:

One piece of advise : be lazy ! 一条建议:懒惰!
if you want to present a lot of views in a scrollView, don't load them all. 如果要在scrollView中显示大量视图,请不要全部加载它们。 The best practice for this is to use a UITableView . 最好的做法是使用UITableView If you know the height of each cell before drawing them on screen, you can implement this method 如果在屏幕上绘制每个单元格之前知道每个单元格的高度,则可以实现此方法

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

in your Tableview Datasource. 在Tableview数据源中。 If you want to use a UIScrollView, add your subviews on demand when the user scroll. 如果要使用UIScrollView,请在用户滚动时按需添加子视图。 The best approach is to implement the delegate method : 最好的方法是实现委托方法:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate

you can make a custom UIView and in that you can make all that you want and simply add your custom view in cellForRowAtIndexPath as 你可以制作一个自定义的UIView ,并且你可以制作你想要的所有东西,只需在cellForRowAtIndexPath添加你的自定义视图

[cell.contentView addSubview:yourcustomview];

the code is 代码是

CV = [[CustomView alloc] initWithFrame:CGRectMake(0, 0, 320, heightofviewyouwant)];
CV.delegate = self;
cell.selectionStyle =  UITableViewCellAccessoryNone;
[CV setTitle:[[yourarray objectAtIndex:indexPath.row]objectForKey:@"yourkey"]]; 
CV.backgroundColor = [UIColor whiteColor];   
[cell.contentView addSubview:CV]; 

return cell;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM