我正在尝试创建一个ViewController,它有可滑动的页面(android类似标签)页面。这些页面本身将包含滚动视图(垂直)和多个视图,这些视图将根据响应类型动态添加(每个页面的不同网络调用)。我不能使用PageViewController,因为我希望页面只占屏幕的一半。
关于CollectionView的问题-
关于ScrollView的问题-
每个页面中的数据将是4-10个堆栈视图,每个堆栈视图包含2-10个图像/标签,或者仅仅是一个集合视图。
PSS -标签总数不超过10个,最少为1个
发布于 2018-07-27 08:56:28
我用collectionView实现了它,因为它应该更有效地使用资源。但是我们需要缓存视图控制器的状态。下面是一个例子
假设您有控制器A,它包含带有单元格的collectionView和子控制器。然后在单元格中逐行
....
var childrenVC: [Int: UIViewController] = [:]
....
// cell for row
let cell: ChildControllerCell = collectionView.dequeueReusableCell(for: indexPath)
if let childController = childrenVC[indexPath.row] {
cell.contentView.addSubview(childController.view)
childController.view.frame = cell.contentView.frame
} else {
let childViewController = ChildViewController()
addChildViewController(childViewController)
childViewController.didMove(toParentViewController: self)
cell.contentView.addSubview(childController.view)
childController.view.frame = cell.contentView.frame
childrenVC[indexPath.row] = childViewController
cell.childVC = childViewController
}
return cell
....
class ChildControllerCell: UICollectionViewCell {
var childVC: UIViewController?
override func prepareForReuse() {
super.prepareForReuse()
if !contentView.subviews.isEmpty {
childVC?.willMove(toParentViewController: nil)
childVC?.view.removeFromSuperview()
childVC?.removeFromParentViewController()
}
}
}https://stackoverflow.com/questions/51532336
复制相似问题