[英]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.