gpt4 book ai didi

ios - 将数据从 locationmanager(..didrangbeacons) 传递到 collectionview(...cellforitemat)

转载 作者:行者123 更新时间:2023-11-28 15:38:43 25 4
gpt4 key购买 nike

每次 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
}

提前致谢

最佳答案

让您的 View Controller 充当位置管理器的委托(delegate)。将对您的 View Controller 调用 locationManager(_:didRangeBeacons:in:)。然后它可以更新一个 INSTANCE 变量(不是全局变量)来保存新的信标信息列表,并告诉 Collection View 更新它的内容。

关于ios - 将数据从 locationmanager(..didrangbeacons) 传递到 collectionview(...cellforitemat),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43990224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com