使用uiscrollview和uiview创建TableViewController

时间:2017-10-12 09:14:21

标签: ios objective-c uitableview

如何使用scrollview和viewcontroller自己创建tableViewController。我实际上尝试通过向scrollview和其他类似的东西添加可重用的视图。但我被卡住了。

请提供链接或想法,因为我是ios编程的新手。

2 个答案:

答案 0 :(得分:0)

创建UIViewController并在其视图中添加UITableView作为子视图。使ViewController符合UITableViewDelegateUITableViewDataSource协议,并将其设置为tableView的委托和dataSource。您可以将UITableViewCell添加到tableView。

这是一个循序渐进的教程: https://www.journaldev.com/14180/ios-custom-tableview-images-checkmarks

请查看UITableViewDataSource linkUITableViewDelegate link

的文档

答案 1 :(得分:0)

Here is how I would approach it:

  1. Create components and implement UIScrollViewDelegate in your ViewController
  2. Calculate content size of your scrollView (sum of height of the subviews; sum of widths of your subview).
  3. Create a method that determines what views should be added and removed on the scroll view based on it's content offset and frame (for example initially you may have content offset of 0.0 and a frame size of 50/100 so only two suviews of 50/50 will fit in a vertical row)
  4. Add your first visible views (in the visible part of the scroll view add subviews based " on what view goes where " )
  5. use the func scrollViewDidScroll(_ scrollView: UIScrollView) to call the method you created at step 3
  6. adjust and and refactor