I have to update collectionview every time that locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion)
do a cycle, so i thought to pass beacons
variables from it to collectionview, how con i do it without using global variables. Here's the code:
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
}
Thanks in advance
Make your view controller serve as the delegate of the location manager. The call to locationManager(_:didRangeBeacons:in:)
will be made to your view controller. It can then update an INSTANCE variable (not a global variable) to hold the new list of beacon information and tell the collection view to update it's contents.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.