今天遇到多页面展示,切换页面展示信息显示错乱。
解决方法:
移除上次添加的页面,再次添加就好了。
代码如下:
private func setupCustomerInfoPageView() {
// 创建PageStyle,设置样式
let style = PageStyle()
style.isTitleViewScrollEnabled = true
style.isTitleScaleEnabled = false
style.titleViewBackgroundColor = UIColor.black
style.titleViewHeight = 46
style.titleSelectedColor = UIColor.customRedColor
if models.count == 0 {
let model = GuestInfoModel()
model.levelName = "未登录"
models = [model]
}
// 先移除
for vc in self.children.reversed() {
if vc != nil {
vc.view.removeFromSuperview()
vc.removeFromParent()
}
}
for i in 0..<models.count {
let controller = CustomerInfoController()
controller.index = i
controller.model = models[i]
addChild(controller)
}
let pageView = PageView(frame: CGRect(x: 0, y: 0, width: kScaleWidth(534), height: kScaleHeight(390)), style: style, models: models, childViewControllers: children)
view.addSubview(pageView)
}