gpt4 book ai didi

ios - 将一组位置从 tableview 传递到 mapview

转载 作者:行者123 更新时间:2023-11-29 02:20:07 25 4
gpt4 key购买 nike

这是我的 TableView Controller 。我在要传递的类中声明了我的 mapSearch 数组。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)


let selectedMap = mapSearch[indexPath.row]

let mapviewDestination = MapViewController()
mapviewDestination.mapString = selectedMap

performSegueWithIdentifier("showDetails", sender: tableView)


}

这是我的 mapViewController 代码。

var mapString : String?

实际搜索。

var request = MKLocalSearchRequest()
request.naturalLanguageQuery = mapString
request.region = self.placeMap.region
var search:MKLocalSearch = MKLocalSearch.init(request: request)
search.startWithCompletionHandler {
(response:MKLocalSearchResponse!, error:NSError!) in
if !(error != nil) {
var placemarks:NSMutableArray = NSMutableArray()
for item in response.mapItems {
placemarks.addObject((item as MKMapItem).placemark)
}
self.placeMap.removeAnnotations(self.placeMap.annotations)
self.placeMap.showAnnotations(placemarks, animated: true)
} else {

}
}

我的问题是,当我运行模拟器时,它不会根据 mapString 进行搜索。

欢迎任何想法!

编辑:

我一直在尝试这个,但没有成功:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
tableView.deselectRowAtIndexPath(indexPath, animated: true)

let selectedMap = mapSearch[indexPath.row]

performSegueWithIdentifier("showDetails", sender: self)


}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "showDetails" {
var mapController = segue.destinationViewController as MapViewController
mapController.mapString = mapSearch
}
}

最佳答案

您确定 didSelectRowAtIndexPath 中的 mapviewDestination 没有被释放和销毁吗?您正在为它分配一个 mapString 但您没有对它执行任何操作。

搜索是在 nil(或空)字符串上执行的,因为您实际上从未设置过 mapString

如果您需要使用 segues 在两个 View Controller 之间传递数据,您应该使用 UIViewControllerprepareForSegue:sender:(您只需在您的代码中重新实现它呈现 View Controller )。它为您提供了一个指向呈现的 View Controller 的指针,您可以在它出现在屏幕上之前对其进行配置。

关于ios - 将一组位置从 tableview 传递到 mapview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28250192/

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