我以编程方式创建了 Collection View ,并将属性multipleSelectionOn设置为默认值false
请观看我的收藏查看代码:
import UIKit
class GalleryCollectionViewController: UICollectionViewController , UICollectionViewDelegateFlowLayout {
open var multipleSelectionOn:Bool = false
override init(collectionViewLayout layout: UICollectionViewLayout) {
super.init(collectionViewLayout: layout)
collectionView?.collectionViewLayout = layout
collectionView!.register(GalleryCollectionViewCell.self, forCellWithReuseIdentifier: "cell")
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
print(multipleSelectionOn)
}
**//AND SOME ANOTHER CODE**
}
并这样调用它:
let layout = UICollectionViewFlowLayout()
let galleryColVC = GalleryCollectionViewController(collectionViewLayout: layout)
galleryColVC.multipleSelectionOn = true
let galleryNav = UINavigationController(rootViewController: galleryColVC)
self.present(galleryNav, animated: true, completion: nil)
但是更改调用代码中的属性未设置,并且只显示 false 值。
如何解决这个问题?
最佳答案
这对我有用。
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let galleryColVC = storyboard.instantiateViewController(withIdentifier: "GalleryViewController") as! GalleryViewController
galleryColVC.multipleSelectionOn = true
present(galleryColVC, animated: true, completion: nil)
将您的 Storyboard ID 添加为 GalleryViewController 的“GalleryViewController”。
关于ios - 如何更改 iOS Swift 3 实例类中的 value 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45252105/