Когда я нажимаю на штифт карты, представление о деталях на другом контроллере представления для выбранного пин -контакта ресторана не показан. Я думаю, что это происходит из-за задачи блока, который я использую.
Это приложение для iOS, с минимальным развертыванием iOS 18.2. Как это исправить? В конце блока задачи, и я использовал @mainactor для обеих функций, и он все еще не работал. Я также включил операторы печати из консоли, когда запускается минимальный воспроизводимый пример.import UIKit
func startTaskOfGettingInitialMapVenueData() {
//Get venues data.
Task {
guard let mapVenues = try? await getMapVenues() else {return}
self.mapVenues = mapVenues
//Print Check.
print("Print Check. At the end of the Task block, and still within the Task block. mapVenues:", mapVenues)
self.showMapVenuesAsPins(mapVenues: self.mapVenues)
}
< /code>
MapViewContoller.swift:
import UIKit
import MapKit
class MapViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var mapView: MKMapView!
var mapVenues: [InitialMapVenue] = []
//var mapVenues: [MapVenue] = []
override func viewDidLoad() {
super.viewDidLoad()
//centerOfRegion is Downtown San Francisco.
let centerOfRegion = CLLocationCoordinate2D(
latitude: 37.77531597108412, longitude: -122.42265827001113)
let region = MKCoordinateRegion(center: centerOfRegion, latitudinalMeters: 500, longitudinalMeters: 500)
mapView.setRegion(region, animated: true)
startTaskOfGettingInitialMapVenueData()
}
func startTaskOfGettingInitialMapVenueData() {
//Get venues data.
Task {
guard let mapVenues = try? await getMapVenues() else {return}
self.mapVenues = mapVenues
//Print Check.
print("Print Check. At the end of the Task block, and still within the Task block. mapVenues:", mapVenues)
self.showMapVenuesAsPins(mapVenues: self.mapVenues)
}
//Print Check.
print("Print Check. After the Task block, and right outside the Task block, and right before the for loop that shows each venue in venues as an annotation.")
}
func showMapVenuesAsPins(mapVenues: [InitialMapVenue]) {
//Print Check.
print("Print Check. Inside showMapVenuesAsPins function, and before the for loop.")
for element in mapVenues {
mapView.addAnnotation(element)
}
}
func getMapVenues() async throws -> [InitialMapVenue] {
let generatedMapVenues = [InitialMapVenue(name: "Rich Table", address: "199 Gough St, San Francisco, CA 94102", latitude: 37.774891876134795, longitude: -122.4227253023382, coordinate: CLLocationCoordinate2D(latitude: 37.774891876134795, longitude: -122.4227253023382)), InitialMapVenue(name: "The Bird", address: "406 Hayes St, San Francisco, CA 94102", latitude: 37.77696798656497, longitude: -122.42325276271241, coordinate: CLLocationCoordinate2D(latitude: 37.77696798656497, longitude: -122.42325276271241))]
return generatedMapVenues
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let restaurantPinAnnotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "MyMarker")
restaurantPinAnnotationView.markerTintColor = UIColor.blue
return restaurantPinAnnotationView
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let mapVenue = view.annotation as? InitialMapVenue else { return }
presentDetailViewFromSelectedRestaurantPinFromMapModal(mapVenue: mapVenue)
}
private func presentDetailViewFromSelectedRestaurantPinFromMapModal(mapVenue: InitialMapVenue) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let detailViewForSelectedRestaurantFromMapVC = storyboard.instantiateViewController(identifier: "DetailViewForSelectedRestaurantFromMapViewController") as! DetailViewForSelectedRestaurantFromMapViewController
let nav = UINavigationController(rootViewController: detailViewForSelectedRestaurantFromMapVC)
nav.setNavigationBarHidden(true, animated: false)
nav.modalPresentationStyle = .pageSheet
if let sheet = nav.sheetPresentationController {
sheet.detents = [.medium(), .large()]
sheet.prefersGrabberVisible = true
}
detailViewForSelectedRestaurantFromMapVC.theMapVenue = mapVenue
present(nav, animated: true, completion: nil)
}
}
class InitialMapVenue: NSObject, MKAnnotation {
var name: String?
var address: String?
var latitude: Double?
var longitude: Double?
var coordinate: CLLocationCoordinate2D
var title: String? {
return name
}
init(name: String?,
address: String?,
latitude: Double?,
longitude: Double?,
coordinate: CLLocationCoordinate2D) {
self.name = name
self.address = address
self.latitude = latitude
self.longitude = longitude
self.coordinate = coordinate
}
}
< /code>
DetailViewForSelectedRestaurantFromMapViewController.swift:
import UIKit
class DetailViewForSelectedRestaurantFromMapViewController: UIViewController {
var theMapVenue: InitialMapVenue!
override func viewDidLoad() {
super.viewDidLoad()
}
}
< /code>
Print Statements from the console:
*Log Statement saying a certain file is missing.*
Print Check. After the Task block, and right outside the Task block, and right before the for loop that shows each venue in venues as an annotation.
*Log Statement.*
Print Check. At the end of the Task block, and still within the Task block. mapVenues: [, ]
Print Check. Inside showMapVenuesAsPins function, and before the for loop.
Print Check. Inside showMapVenuesAsPins function, and after the for loop.
*Log Statement.*
*Log Statement.*
Подробнее здесь: https://stackoverflow.com/questions/796 ... -a-map-pin
Подробнее представление о другом контроллере представления, не отображаемое после выбора штифта карты, возможно, из -за ⇐ IOS
Программируем под IOS
1748598141
Anonymous
Когда я нажимаю на штифт карты, представление о деталях на другом контроллере представления для выбранного пин -контакта ресторана не показан. Я думаю, что это происходит из-за задачи блока, который я использую.
Это приложение для iOS, с минимальным развертыванием iOS 18.2. Как это исправить? В конце блока задачи, и я использовал @mainactor для обеих функций, и он все еще не работал. Я также включил операторы печати из консоли, когда запускается минимальный воспроизводимый пример.import UIKit
func startTaskOfGettingInitialMapVenueData() {
//Get venues data.
Task {
guard let mapVenues = try? await getMapVenues() else {return}
self.mapVenues = mapVenues
//Print Check.
print("Print Check. At the end of the Task block, and still within the Task block. mapVenues:", mapVenues)
self.showMapVenuesAsPins(mapVenues: self.mapVenues)
}
< /code>
MapViewContoller.swift:
import UIKit
import MapKit
class MapViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var mapView: MKMapView!
var mapVenues: [InitialMapVenue] = []
//var mapVenues: [MapVenue] = []
override func viewDidLoad() {
super.viewDidLoad()
//centerOfRegion is Downtown San Francisco.
let centerOfRegion = CLLocationCoordinate2D(
latitude: 37.77531597108412, longitude: -122.42265827001113)
let region = MKCoordinateRegion(center: centerOfRegion, latitudinalMeters: 500, longitudinalMeters: 500)
mapView.setRegion(region, animated: true)
startTaskOfGettingInitialMapVenueData()
}
func startTaskOfGettingInitialMapVenueData() {
//Get venues data.
Task {
guard let mapVenues = try? await getMapVenues() else {return}
self.mapVenues = mapVenues
//Print Check.
print("Print Check. At the end of the Task block, and still within the Task block. mapVenues:", mapVenues)
self.showMapVenuesAsPins(mapVenues: self.mapVenues)
}
//Print Check.
print("Print Check. After the Task block, and right outside the Task block, and right before the for loop that shows each venue in venues as an annotation.")
}
func showMapVenuesAsPins(mapVenues: [InitialMapVenue]) {
//Print Check.
print("Print Check. Inside showMapVenuesAsPins function, and before the for loop.")
for element in mapVenues {
mapView.addAnnotation(element)
}
}
func getMapVenues() async throws -> [InitialMapVenue] {
let generatedMapVenues = [InitialMapVenue(name: "Rich Table", address: "199 Gough St, San Francisco, CA 94102", latitude: 37.774891876134795, longitude: -122.4227253023382, coordinate: CLLocationCoordinate2D(latitude: 37.774891876134795, longitude: -122.4227253023382)), InitialMapVenue(name: "The Bird", address: "406 Hayes St, San Francisco, CA 94102", latitude: 37.77696798656497, longitude: -122.42325276271241, coordinate: CLLocationCoordinate2D(latitude: 37.77696798656497, longitude: -122.42325276271241))]
return generatedMapVenues
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let restaurantPinAnnotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "MyMarker")
restaurantPinAnnotationView.markerTintColor = UIColor.blue
return restaurantPinAnnotationView
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let mapVenue = view.annotation as? InitialMapVenue else { return }
presentDetailViewFromSelectedRestaurantPinFromMapModal(mapVenue: mapVenue)
}
private func presentDetailViewFromSelectedRestaurantPinFromMapModal(mapVenue: InitialMapVenue) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let detailViewForSelectedRestaurantFromMapVC = storyboard.instantiateViewController(identifier: "DetailViewForSelectedRestaurantFromMapViewController") as! DetailViewForSelectedRestaurantFromMapViewController
let nav = UINavigationController(rootViewController: detailViewForSelectedRestaurantFromMapVC)
nav.setNavigationBarHidden(true, animated: false)
nav.modalPresentationStyle = .pageSheet
if let sheet = nav.sheetPresentationController {
sheet.detents = [.medium(), .large()]
sheet.prefersGrabberVisible = true
}
detailViewForSelectedRestaurantFromMapVC.theMapVenue = mapVenue
present(nav, animated: true, completion: nil)
}
}
class InitialMapVenue: NSObject, MKAnnotation {
var name: String?
var address: String?
var latitude: Double?
var longitude: Double?
var coordinate: CLLocationCoordinate2D
var title: String? {
return name
}
init(name: String?,
address: String?,
latitude: Double?,
longitude: Double?,
coordinate: CLLocationCoordinate2D) {
self.name = name
self.address = address
self.latitude = latitude
self.longitude = longitude
self.coordinate = coordinate
}
}
< /code>
DetailViewForSelectedRestaurantFromMapViewController.swift:
import UIKit
class DetailViewForSelectedRestaurantFromMapViewController: UIViewController {
var theMapVenue: InitialMapVenue!
override func viewDidLoad() {
super.viewDidLoad()
}
}
< /code>
Print Statements from the console:
*Log Statement saying a certain file is missing.*
Print Check. After the Task block, and right outside the Task block, and right before the for loop that shows each venue in venues as an annotation.
*Log Statement.*
Print Check. At the end of the Task block, and still within the Task block. mapVenues: [, ]
Print Check. Inside showMapVenuesAsPins function, and before the for loop.
Print Check. Inside showMapVenuesAsPins function, and after the for loop.
*Log Statement.*
*Log Statement.*
Подробнее здесь: [url]https://stackoverflow.com/questions/79645221/detail-view-on-a-different-view-controller-not-showing-after-selecting-a-map-pin[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия