我遇到了一些问题:当解除ViewController在当前上下文中显示图片时,屏幕会不时冻结。
有人可以就如何解决这个问题向我提供一些见解吗?
我尝试使用暂停按钮检查主线程,但没有找到任何不寻常的东西。
我的代码示例如下:
Tabwidget
SalePopupViewController:
import UIKit
class ViewControllerCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor.white
addSubview(showPhotoButton)
showPhotoButton.leftAnchor.constraint(equalTo: leftAnchor, constant: 200).isActive = true
showPhotoButton.bottomAnchor.constraint(equalTo: topAnchor, constant: 160).isActive = true
showPhotoButton.heightAnchor.constraint(equalToConstant: 50).isActive = true
showPhotoButton.widthAnchor.constraint(equalToConstant: 70).isActive = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
lazy var showPhotoButton: UIButton = {
let button = UIButton(type: .system)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("Show", for: .normal)
button.addTarget(self, action: #selector(showSale), for: .touchUpInside)
button.setTitleColor(UIColor(r: 120, g: 80, b: 255), for: .normal)
return button
}()
@objc func showSale() {
let popupViewController = SalePopupViewController()
popupViewController.modalPresentationStyle = .overCurrentContext
popupViewController.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
window!.rootViewController?.present(PopupViewController, animated: true, completion: nil)
}
}
答案 0 :(得分:1)
首先,为什么你要展示来自SELECT
hs.reason
,max(hs.STATUS)
,sum(duration / 60) AS minutes
,max(rtrim(hr.NAME)) AS reasonname
FROM hist_statusevents AS hs
INNER JOIN hist_reasontable AS hr ON hr.shiftindex = hs.shiftindex
AND hr.reason = hs.reason
INNER JOIN hist_exproot AS he ON he.shiftindex = hs.shiftindex
WHERE shiftdate = '2017-12-13'
AND eqmt IN (
'ex02'
,'ex03'
,'ex04'
,'ex05'
,'ex06'
,'ex07'
)
AND hs.STATUS <> 2
AND hs.STATUS <> 1
AND hr.NAME NOT LIKE ('SHIFT CHANGE')
AND hs.reason IN (
'7005'
,'5010'
,'6615'
,'6705'
)
GROUP BY
hs.reason
ORDER BY duration DESC
的弹出窗口,而不是你从中调用它的视图控制器?只需使用window!.rootViewController?
代替。
第二件事是弱者本身是完全没有必要的,因为没有办法让自己从记忆中释放出来,但是你的解雇按钮仍然存在,因此它可以强有力地提及自我,使它变得微弱并没有任何区别。
修改强>
所以我没有看到ViewControllerCell是一个集合视图单元格。 现在解决方案有所不同:您有几个选项,1。当您在indexPath函数中为项目执行单元格时,将viewController引用传递给每个单元格
present(PopupViewController, animated: true, completion: nil)
} }
当然你必须在collectionViewCell
中设置一个public varfunc collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
if let cell = collectionView.dequeueReusableCell(withIdentifier identifier: String) as? ViewControllerCell {
//do your thing here
cell.parentViewController = self
//。如果你想使用特定的功能。如果只出现那么你很好
最后你在场的地方使用parentViewController.present(....)