我的UIScrollView有3倍的屏幕尺寸宽度,我有3个表格视图。出于某种原因,当我开始水平滚动时,内容会在某些时间点消失。但桌子在屏幕上(我可以弄明白,因为我设置表背景颜色,可以看到它)。此外,我确实打印了行数并存在。这是我的代码:
func createTables(){
for i in 0...2 {
var tv : UITableView
var adapter : CDRTableAdapter
var tvVm : MainTableViewModel
let offset = (CGFloat(i) * CGFloat(Helper.ScreenSize.width))
print("offset \(offset)")
/* View model */
tvVm = MainTableViewModel()
/* Table view */
adapter = CDRTableAdapter(model:tvVm as CDTableAdapterViewModel, managedVC: self)
let dct = ["EmptyHeightItem" : "EmptyHeightCell", "MenuItem" : "MenuCell"]
tv = UITableView(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
tv.separatorStyle = .none
if (i == 1){
tv.backgroundColor = .yellow
} else {
tv.backgroundColor = .red
}
tv.showsVerticalScrollIndicator = false
tv.mapTableViewWithCellsDictionary(dictionary: dct)
tv.dataSource = adapter
tv.delegate = adapter
tv.estimatedRowHeight = 80
tv.rowHeight = UITableViewAutomaticDimension
self.mainContainerView.addSubview(tv)
tv.snp.makeConstraints { (make) in
make.top.equalTo(self.segmentioView.snp.bottom)
make.bottom.equalTo(self.mainContainerView)
make.left.equalTo(self.mainContainerView).offset(offset)
make.width.equalTo(Helper.ScreenSize.width)
}
}
}
extension UITableView {
func mapTableViewWithCellsDictionary(dictionary : [String : String]) -> Void {
for (key, _) in dictionary {
let cellClassStr = "\(Helper.appName).\(dictionary[key]!)"
self.register(NSClassFromString(cellClassStr), forCellReuseIdentifier: key)
}
}
}
所以,如果有人在遇到问题之前请帮忙。 感谢