【发布时间】:2017-10-14 20:55:50
【问题描述】:
每次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
}
提前致谢
【问题讨论】:
-
位置管理器是在一个单独的类中还是在同一个视图控制器中?
-
同一个viewController
-
如果是同一个视图控制器,您可以在视图控制器中创建一个属性并设置它。但是,将它放在不同的类中并遵循邓肯的回答会更干净
标签: ios swift xcode uicollectionview cllocationmanager