IOS implements best practice for viewing long scrolls

Hi, I would use a very long scroll view for a forum-like presentation, creating something similar to this image.

could this be implemented using a table view (given the not-so-defined borders between cells and some views overlapping other cells), or should I write a long scroll view with many subviews (memory management?)? Thanks

+4
source share
3 answers

Use a UITableView , and it would be better if you subclassed UITableViewCell and used the layoutSubviews method to adjust the view when adjusting the cell size. Resize the cell to fit the content present in it.

Check out the links below:

+10
source

One tip: be lazy!
if you want to present many views in scrollView, do not load all of them. Best practice for this is to use a UITableView . If you know the height of each cell before you draw it on the screen, you can implement this method

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

in your tableview data source. If you want to use UIScrollView, add your child objects as requested when the user scrolls. The best approach is to implement the delegate method:

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

you can create a custom UIView and in it you can do whatever you want and just add your custom view to cellForRowAtIndexPath as

[cell.contentView addSubview:yourcustomview];

the code

 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; 
+3
source

Source: https://habr.com/ru/post/1494913/


All Articles