ios - 如何更改 iOS Swift 3 实例类中的 value 属性?

标签 ios swift class swift3 properties

我以编程方式创建了 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/

相关文章:

c# - Xamarin.iOS Objective-C 绑定(bind)错误

iphone - "Object 0x84be00 of class NSCFString autoreleased with no pool in place - just leaking"- 但在应用程序的第一行!

iOS App 一键闪退

swift - Realm Swift Migration 添加主键 - 不写入数据

php - 将应用程序与应用程序库、共享库、组件等分离

ios - 将 ViewController View 添加为 subview 的错误框架

ios - 子类化 UIButton 以像标签一样设置值

ios - PFQuery - 如何获取 NSError?

java - getClassHierarchy() 方法

javascript - 在 javascript 中扩展 Promise