在一个iOS/SWIFT项目中,如何防止页面的流程压倒其过渡到的页面?
我的意思是您在第A页上。按钮按导航控制器到第B。A页上的过程非常密集且压倒性页面B到产生错误的UI结果(重复的单元格或缺失单元格)
i在大约100次测试中仅观察到这些错误的结果两次。当我按下一个疯狂的按钮时,他们俩都发生了时间页B加载。
我最初以为我在B页上遇到了种族问题,但我不认为这可能是原因,因为此错误仅在A页极不知所措时才发生。我不希望在第B页上使用骨骼视图。以下是第B页中的代码,该代码确定了要显示的单元格的用户。这两个错误,其中1)复制用户的单元格和2)并非所有用户都在单元格中表示。
在ViewDidload中:
if CLLocationManager.locationServicesEnabled() {
switch(CLLocationManager.authorizationStatus()) {
case .authorizedAlways, .authorizedWhenInUse:
print("Access")
locationManager.delegate = self
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
}
let uid = Auth.auth().currentUser!.uid
let thisUserRef = Database.database().reference().child("user").child(uid)
let myuserRef = thisUserRef.child("userWhoLike")
var handle: UInt = 0
handle = myuserRef.queryLimited(toLast: 30).observe(DataEventType.value, with: { snapshot in
print("kkkkk")
func decode(autoId: String) -> TimeInterval {
...
return TimeInterval(exactly: timestamp)!
}
let uniqueArray1 = snapshot.children.allObjects as! [DataSnapshot]
let userArray = Array(Set(uniqueArray1))
for person4 in userArray where uid == Auth.auth().currentUser?.uid {
self.dg.enter()
let personUid = person4.value as! String
let planDict18 = person4.key
let time22 = decode(autoId: planDict18)
let time11 = Int(time22)
self.dg.leave()
self.dg.notify(queue: .main) {
let date = Date(timeIntervalSince1970: TimeInterval(time11)/1000.0)
if Calendar.current.isDateInToday(date){
self.printPersonInfo(uid: personUid)
}
}
}
DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
let ref = Database.database().reference().child("user")
ref.removeObserver(withHandle: handle)
ref.removeObserver(withHandle: self.handleA)
}
})
case .notDetermined:
print("Location services are not enabled")
} else {
print("Location services are not enabled")
}
What I mean is you are on page A. A button press segues via Navigation Controller to page B. The processes on page A are very intensive and overwhelm page B to the point that it produces wrong UI results (duplicate cells or missing cells)
I have only observed these wrong results twice in about 100 tests. They both happened when I pressed buttons on page A like crazy, a second after loading, then immediately pressing the button to go to page B. I am certain these 2 times happened because page A had to process so much and was not done by the time page B was loaded.
I initially thought I had a race problem on page B, but I don't believe that could be the cause, since this error only happened when page A was extremely overwhelmed. I do not wish to use a skeleton view on page B. Anyway below is the code in page B that determines the users for which cells are to be displayed. The two error where 1) duplicate cells of users and 2) not all users being represented in a cell.
In viewDidLoad:
if CLLocationManager.locationServicesEnabled() {
switch(CLLocationManager.authorizationStatus()) {
case .authorizedAlways, .authorizedWhenInUse:
print("Access")
locationManager.delegate = self
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
}
let uid = Auth.auth().currentUser!.uid
let thisUserRef = Database.database().reference().child("user").child(uid)
let myuserRef = thisUserRef.child("userWhoLike")
var handle: UInt = 0
handle = myuserRef.queryLimited(toLast: 30).observe(DataEventType.value, with: { snapshot in
print("kkkkk")
func decode(autoId: String) -> TimeInterval {
...
return TimeInterval(exactly: timestamp)!
}
let uniqueArray1 = snapshot.children.allObjects as! [DataSnapshot]
let userArray = Array(Set(uniqueArray1))
for person4 in userArray where uid == Auth.auth().currentUser?.uid {
self.dg.enter()
let personUid = person4.value as! String
let planDict18 = person4.key
let time22 = decode(autoId: planDict18)
let time11 = Int(time22)
self.dg.leave()
self.dg.notify(queue: .main) {
let date = Date(timeIntervalSince1970: TimeInterval(time11)/1000.0)
if Calendar.current.isDateInToday(date){
self.printPersonInfo(uid: personUid)
}
}
}
DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
let ref = Database.database().reference().child("user")
ref.removeObserver(withHandle: handle)
ref.removeObserver(withHandle: self.handleA)
}
})
case .notDetermined:
print("Location services are not enabled")
} else {
print("Location services are not enabled")
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论