override func viewDidLoad() {
super.viewDidLoad()
tblView.estimatedRowHeight = 50
tblView.rowHeight = UITableViewAutomaticDimension
tblView.register(UINib(nibName: "SegmentedAttachmentCell", bundle: Bundle.main ), forCellReuseIdentifier: "Cell")
iphoneCheck () // Iphone x Check
initalSegmentSelected () // To Show First Index
}
func initalSegmentSelected () {
self.segmentCtrl?.selectedSegmentIndex = 0
screen = screenType.Media
self.screenTypeData()
}
//MARK:- SegmentControllerUI
func showTopSegmentControllerOnNavigationBar()
{
let appearance = SMSegmentAppearance()
appearance.segmentOnSelectionColour = UIColor.DTColor()
appearance.segmentOffSelectionColour = UIColor.clear
appearance.titleOnSelectionFont = UIFont.systemFont(ofSize: 15.0)
appearance.titleOffSelectionFont = UIFont.systemFont(ofSize: 15.0)
appearance.titleOnSelectionColour = UIColor.white
appearance.titleOffSelectionColour = UIColor.white
appearance.contentVerticalMargin = 7.0
segmentCtrl = SMSegmentView(frame: CGRect(x: 10.0, y: 4.0, width: UIScreen.main.bounds.size.width-20.0, height: 36.0), dividerColour: UIColor.DTColor(), dividerWidth: 3.0, segmentAppearance: appearance)
segmentCtrl!.addTarget(self, action: #selector(ChatAttachmentsViewController.selectSegmentInSegmentView(_:)), for: .valueChanged)
segmentCtrl!.addSegmentWithTitle(title: "Media", onSelectionImage: nil, offSelectionImage: nil,badgeCount: nil)
segmentCtrl!.addSegmentWithTitle(title: "Files", onSelectionImage: nil, offSelectionImage: nil,badgeCount: nil)
segmentCtrl!.layer.borderColor = UIColor.DTColor().cgColor
segmentCtrl!.layer.borderWidth = 2.0
segmentCtrl!.layer.cornerRadius = 5
segmentController.addSubview(segmentCtrl!)
segmentController.backgroundColor = UIColor.LTColor()
}
// Setting Table
func screenTypeData() {
if screen == screenType.Media {
tblView.isHidden = true
self.tblView.isScrollEnabled = false
attachmentsCollectionView.isHidden = false
self.attachmentsCollectionView.isScrollEnabled = true
self.attachmentsCollectionView.reloadData()
}
else if screen == screenType.Document {
tblView.dataSource = self
tblView.delegate = self
attachmentsCollectionView.isHidden = true
self.attachmentsCollectionView.isScrollEnabled = false
tblView.isHidden = false
self.tblView.isScrollEnabled = true
self.tblView.reloadData()
}
}
在screentypedata中设置tableview数据源和委托是否正确?或者我应该在viewdidload上设置它(问题是它在第一次点击时加载表也导致了很多时间,所以如何优化它)
我怀疑的问题: