2017-07-22 6 views
0

私はプログラム的コレクションビューを作り、設定プロパティmultipleSelectionOnデフォルト値で
を私のコレクションビューコードご覧ください:iOS Swift 3でインスタンスクラスのvalueプロパティを変更するには?

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) 

しかし変更を呼び出しコードのプロパティが設定されていないと私を示すだけ値。

これを修正するにはどうすればよいですか?

+0

を? –

+0

はいそれを変更してアクセスしたいです@UdayaSri –

+0

self.present(galleryNav、animated:true、completion:nil)の後でtrueに設定してみてください。それは動作するはずです。 –

答えて

0

この作品は私のためのものです。

let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    let galleryColVC = storyboard.instantiateViewController(withIdentifier: "GalleryViewController") as! GalleryViewController 
galleryColVC.multipleSelectionOn = true 
present(galleryColVC, animated: true, completion: nil) 

GalleryViewControllerの「GalleryViewController」としてストーリーボードIDを追加します。

0

私は解決策が見つかりました:あなたはgalleryColVCでmultipleSelectionOn値を取得しますか、またはあなたが本当のことを割り当てた後、あなたがmultipleSelectionOnにアクセスしない場所

var multipleSelectionOn:Bool = false { 
     didSet { 
      print("VALUE IS: \(multipleSelectionOn)") 
      //Get true 
     } 
    } 
関連する問題