For managing the content views (lists) associated with each segment, it is highly recommended to use JXSegmentedListContainerView instead of a raw UIScrollView.
Advantages of JXSegmentedListContainerView:
- High level of abstraction and centralized code.
- Lazy Loading: Lists are initialized only when they are displayed, improving performance.
- Supports
UICollectionView as a container for better memory management. - Supports the full lifecycle methods of the list items.
1. Initialize the Container
Associate the container with the segmentedView using the listContainer property.
2. Implement JXSegmentedListContainerViewDataSource
Provide the number of lists and the instance that conforms to JXSegmentedListContainerViewListDelegate for each index.
3. Implement JXSegmentedListContainerViewListDelegate
Your list items (can be UIView or UIViewController) must implement this to provide their view and lifecycle callbacks.
// 1. Initialize JXSegmentedListContainerView
listContainerView = JXSegmentedListContainerView(dataSource: self)
view.addSubview(self.listContainerView)
// Associate the list with the segmented view
segmentedView.listContainer = listContainerView
// 2. Implement JXSegmentedListContainerViewDataSource
func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
return segmentedDataSource.titles.count
}
func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
return ListBaseViewController()
}
// 3. Implement JXSegmentedListContainerViewListDelegate
// For a ViewController, return vc.view. For a View, return self.
func listView() -> UIView {
return view
}
func listWillAppear() {}
func listDidAppear() {}
func listDidDisappear() {}
func listDidDisappear() {}