小编Sly*_*oth的帖子

使地图缩放到用户位置和注释(swift 2)

我正在使用mapkit.我希望地图缩放以显示用户的位置和注释点,而不是仅缩放到用户的当前位置.

目前我有:

                            let annotation = MKPointAnnotation()
                            annotation.coordinate = CLLocationCoordinate2DMake(mapLat, mapLon)
                            annotation.title = mapTitle
                            self.map.addAnnotation(annotation)

    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let userLoction: CLLocation = locations[0]
    let latitude = userLoction.coordinate.latitude
    let longitude = userLoction.coordinate.longitude
    let latDelta: CLLocationDegrees = 0.05
    let lonDelta: CLLocationDegrees = 0.05
    let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)
    let location: CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
    let region: MKCoordinateRegion = MKCoordinateRegionMake(location, span)
    self.map.setRegion(region, animated: true)
    self.map.showsUserLocation = true
}
Run Code Online (Sandbox Code Playgroud)

它只是缩放到用户的位置,它被锁定在该位置.当我尝试滚动时,它会直接跳回用户的位置.我究竟做错了什么?如何让用户在不跳回当前位置的情况下缩放或移动地图?

我正在尝试放大以在同一视图上显示注释和用户的位置.即使注释很远,我也希望它能够缩放以显示用户和注释.

annotations mapkit ios swift

9
推荐指数
1
解决办法
8859
查看次数

Tableview首先重用单元格并显示错误数据

你好,我一直有这个问题.我想阻止tableview重用单元格.当我滚动时它会一直显示错误信息然后显示正确的事情,如几毫秒.如何阻止tableview重用单元格或如何重用单元格并使其不这样做.

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return cats.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cellIdentifier = "CategoryTableViewCell"
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! CategoryTableViewCell
    cell.nameLabel.text = cats[indexPath.row].categoryName
    cell.subNameLabel.text = cats[indexPath.row].appShortDesc
    let catImageUrl = cats[indexPath.row].imageUrl
            let url = NSURL(string: "https:\(catImageUrl)")
            let urlRequest = NSURLRequest(URL: url!)
            NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (response, data, error) -> Void in
                if error != nil {
                    print(error)
                } …
Run Code Online (Sandbox Code Playgroud)

xcode ios swift

2
推荐指数
1
解决办法
2888
查看次数

如何让UISearchController等待点击搜索

我正在尝试在我的SWIFT代码中实现搜索。我希望它等到单击搜索按钮后再执行任何操作。到目前为止我所拥有的。

func updateSearchResultsForSearchController(searchController: UISearchController)
{
    self.filteredCats.removeAll(keepCapacity: false)
    filteredCats = art.filter{
        $0.sarticleTitle.lowercaseString.rangeOfString(searchController.searchBar.text!.lowercaseString) != nil
    }
        print(searchController.searchBar.text)
        self.tableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)

用户输入内容后,它将打印出所有信息。我希望它一直等到单击搜索按钮或用户完成所有输入为止。

ios swift uisearchcontroller

2
推荐指数
1
解决办法
1807
查看次数

标签 统计

ios ×3

swift ×3

annotations ×1

mapkit ×1

uisearchcontroller ×1

xcode ×1