簡體   English   中英

將數據從locationmanager(.. didrangbeacons)傳遞到collectionview(…cellforitemat)

[英]Pass data from locationmanager(..didrangbeacons) to collectionview(…cellforitemat)

每當locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion)執行一個循環時,我都必須更新collectionview,所以我想將beacons變量從其傳遞到collectionview,如何在不使用的情況下進行操作全局變量。 這是代碼:

 func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
    if !beacons.isEmpty {
        //do things
    }
    else{
        //do other things
    }
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! buttonBeaconsView

    //i want to use beacons data here


    //cell.backgroundColor = UIColor(white: 1, alpha: 0.8)
    //cell.createButton()
    //cell.layer.masksToBounds = true
    return cell
}

提前致謝

讓您的視圖控制器充當位置管理器的委托。 將會對視圖控制器進行對locationManager(_:didRangeBeacons:in:)的調用。 然后,它可以更新INSTANCE變量(而不是全局變量)以保存新的信標信息列表,並告訴收集視圖更新其內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM