Табличное представление пользовательского интерфейса с ошибкамиIOS

Программируем под IOS
Ответить
Anonymous
 Табличное представление пользовательского интерфейса с ошибками

Сообщение Anonymous »

Я хочу, чтобы представление было похоже на представление таблицы пользовательского интерфейса Apple Maps. Когда вы нажимаете на аннотацию карты, представление таблицы пользовательского интерфейса перемещается вверх вместе с загруженной информацией и становится плавным. Я создал UITableView для загрузки данных из API Yelp и базы данных Firebase. Несмотря на то, что у меня есть данные, загруженные в представление таблицы пользовательского интерфейса, движение таблицы кажется прерывистым. Например, когда я впервые нажимаю на аннотацию карты, появляется окно таблицы пользовательского интерфейса, но в случайном положении, а затем, после загрузки API Yelp, оно снова перемещается в положение по умолчанию. Другое дело, что если я использую жест смахивания до загрузки API Yelp, представление таблицы пользовательского интерфейса переместится соответствующим образом, но затем вернется в исходное положение при загрузке данных API Yelp, после чего мне придется повторить жест смахивания.
Это табличное представление состоит из множества частей, поэтому я приведу список фрагментов кода, которые я использую:
Примечание: Табличное представление пользовательского интерфейса (locationInfoViews) настраивается в ViewDidLoad
Проведение вверх/вниз
func configureGestureRecognizer() {
let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipeGesture))
swipeUp.direction = .up
addGestureRecognizer(swipeUp)

let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipeGesture))
swipeDown.direction = .down
addGestureRecognizer(swipeDown)
}

func animateInputView(targetPosition: CGFloat, completion: @escaping(Bool) -> ()) {
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0, options: .curveEaseInOut, animations: {self.frame.origin.y = targetPosition}, completion: completion)
}

// MARK: - Handlers

@objc func handleSwipeGesture(sender: UISwipeGestureRecognizer) {
if sender.direction == .up {
if expansionState == .Disappeared {
animateInputView(targetPosition: self.frame.origin.y - 100) { (_) in
self.expansionState = .NotExpanded
}
}

if expansionState == .NotExpanded {
animateInputView(targetPosition: self.frame.origin.y - 200) { (_) in
self.expansionState = .PartiallyExpanded
}
}

if expansionState == .PartiallyExpanded {
animateInputView(targetPosition: self.frame.origin.y - 250) { (_) in
self.expansionState = .FullyExpanded
}
}

} else {
if expansionState == .FullyExpanded {
animateInputView(targetPosition: self.frame.origin.y + 250) { (_) in
self.expansionState = .PartiallyExpanded
}
}

if expansionState == .PartiallyExpanded {
animateInputView(targetPosition: self.frame.origin.y + 200) { (_) in
self.expansionState = .NotExpanded
}
}

if expansionState == .NotExpanded {
animateInputView(targetPosition: self.frame.origin.y + 100) { (_) in
self.expansionState = .Disappeared
}
}
}
}

При выборе аннотации информация из Yelp и Firebase будет загружена в представление информации о местоположении, а анимация должна переместиться вверх.
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
self.locationPosts.removeAll()
self.inLocationInfoMode = true

if view.annotation is MKUserLocation {
print("selected self")

} else {

self.selectedAnnotation = view.annotation as? Annotation
let coordinates = selectedAnnotation.coordinate
let coordinateRegion = MKCoordinateRegion(center: coordinates, latitudinalMeters: 1000, longitudinalMeters: 100)
mapView.setRegion(coordinateRegion, animated: true)

self.locationInfoViews.locationTitle = self.selectedAnnotation.title

// Fetch Location Post
guard let currentUid = Auth.auth().currentUser?.uid else {return}

LOCATION_REF.child(self.selectedAnnotation.title).child(currentUid).observe(.childAdded) { (snapshot) in
let postId = snapshot.key
Database.fetchLocationPost(with: postId) { (locationPost) in
self.locationPosts.append(locationPost)

self.locationPosts.sort { (post1, post2) -> Bool in
return post1.creationDate > post2.creationDate
}

self.locationInfoViews.locationResults = self.locationPosts
// self.locationInfoViews.tableView.reloadData()

// Fetch Location Information
guard let locationName = locationPost.locationName else {return}
guard let locationAddress = locationPost.address else {return}

let locationRef = COORDINATES_REF.child(locationName).child(locationAddress)

locationRef.child("mainTypeOfPlace").observe(.value) { (snapshot) in
guard let mainTypeOfPlace = snapshot.value as? String else {return}
// self.locationInfoViews.typeOfPlace = mainTypeOfPlace

locationRef.child("shortAddress").observe(.value) { (snapshot) in
guard let address1 = snapshot.value as? String else {return}

locationRef.child("city").observe(.value) { (snapshot) in
guard let city = snapshot.value as? String else {return}

locationRef.child("state").observe(.value) { (snapshot) in
guard let state = snapshot.value as? String else {return}

locationRef.child("countryCode").observe(.value) { (snapshot) in
guard let country = snapshot.value as? String else {return}

// fetch Yelp API Data
self.service.request(.match(name: locationName, address1: address1, city: city, state: state, country: country)) {
(result) in
switch result {
case .success(let response):
let businessesResponse = try? JSONDecoder().decode(BusinessesResponse.self, from: response.data)
let firstID = businessesResponse?.businesses.first?.id

self.information.request(.BusinessID(id: firstID ?? "")) {
(result) in
switch result {
case .success(let response):
if let jsonResponse = try? JSONSerialization.jsonObject(with: response.data, options: []) as? [String: Any] {
// print(jsonResponse)

if let categories = jsonResponse["categories"] as? Array {
var mainCategory = ""
for category in categories {
mainCategory = category["title"] as? String ?? ""
break
}
self.locationInfoViews.typeOfPlace = mainCategory
}

let price = jsonResponse["price"] as? String ?? ""

if let hours = jsonResponse["hours"] as? Array {
for hour in hours {
let isOpen = hour["is_open_now"] as? Int ?? 0
if isOpen == 1 {
let attributedText = NSMutableAttributedString(string: "open ", attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor(rgb: 0x066C19)])
attributedText.append(NSAttributedString(string: " \(price)", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.black]))
self.locationInfoViews.hoursLabel.attributedText = attributedText
} else {

let attributedText = NSMutableAttributedString(string: "closed ", attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.red])
attributedText.append(NSAttributedString(string: " \(price)", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.darkGray]))
self.locationInfoViews.hoursLabel.attributedText = attributedText
}
}
}
}

case .failure(let error):
print("Error: \(error)")
}
}
case .failure(let error):
print("Error: \(error)")
}
}
}
}
}
}
}

self.locationInfoViews.tableView.reloadData()
}
}

// enable the goButton
if inLocationInfoMode {
locationInfoViews.goButton.isEnabled = true
locationInfoViews.coordinates = selectedAnnotation.coordinate
}

// the movement of the location info view
if self.locationInfoViews.expansionState == .Disappeared {
self.locationInfoViews.animateInputView(targetPosition: self.locationInfoViews.frame.origin.y - 335) { (_) in
self.locationInfoViews.expansionState = .PartiallyExpanded
}
}
}
}


Подробнее здесь: https://stackoverflow.com/questions/593 ... -tableview
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»