Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 401
ʞᴉɯ Avatar asked Dec 05 '22 09:12

ʞᴉɯ


2 Answers

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. Change the cell size according to the content present in it.

Check the below links for this:

  • iOS SDK: Crafting Custom UITableView Cells
  • Customize Table View Cells for UITableView
  • Easy custom UITableView drawing
like image 96
Vivek Sehrawat Avatar answered Dec 27 '22 00:12

Vivek Sehrawat


One piece of advise : be lazy !
if you want to present a lot of views in a scrollView, don't load them all. The best practice for this is to use a 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. If you want to use a UIScrollView, add your subviews on demand when the user scroll. The best approach is to implement the delegate method :

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
like image 37
Toploulou Avatar answered Dec 27 '22 00:12

Toploulou