【问题标题】:Swift - change height of mapview inside a tableViewSwift - 在 tableView 中更改 mapview 的高度
【发布时间】:2015-12-03 13:04:57
【问题描述】:

(看##Edit##) 我是初学者。我使用谷歌,但找不到解决问题的方法。

如何在 tableView 中更改 MapView 的高度?

我的故事板看起来像: click here I cant post pictures

我可以随意更改 MKMapView 的大小,但“在真实/在模拟器中”没有任何改变。

我尝试使用以下方法更改单元格的大小:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
  
    if(indexPath.row == 0) {
         return 500
    }
    
    return 75.0
}

但 indexPath.row=0 是第一个条目“名称:测试”

有人可以解释我如何以及为什么不能更改尺寸吗?如何更改大小?

谢谢你的帮助。

编辑

我尝试了两个不同的单元格(“Map Cell”和“listAllBakeries”),现在它适用于大小。

当我点击一个条目时,“地图单元”上没有更新,而是在“listAllBakeries”上。 More than one Map

代码:

 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    //CODE TO BE RUN ON CELL TOUCH

    //get the Location with latitude and longitude
    var location = CLLocationCoordinate2D(latitude: latitude[indexPath.item], longitude: longitude[indexPath.item])
    
    //resolution
    var span = MKCoordinateSpanMake(0.003, 0.003)
    var region = MKCoordinateRegion(center: location,span:span)
    
    
    //here is the mistake
    let cell2:ListPlacesTableViewCell = tableView.dequeueReusableCellWithIdentifier("MapCell", forIndexPath: indexPath) as! ListPlacesTableViewCell
    
    //some Text about the Place
    var annotation = MKPointAnnotation() 
    annotation.coordinate = location
    annotation.title = namesBakeries[indexPath.item]
    annotation.subtitle = "some Text"
    
    //Zooming inside the map
    cell2.Map.setRegion(region, animated: true)
    cell2.Map.addAnnotation(annotation)
    
}

我真的不明白这一点。我使用了正确的标识符(MapCell),但部分/行是错误的。如何使用正确的部分?

这是我如何填充行/部分的代码

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    
    if(indexPath.section == 0) {
        let cell2:ListPlacesTableViewCell = tableView.dequeueReusableCellWithIdentifier("MapCell", forIndexPath: indexPath) as! ListPlacesTableViewCell
        
        //insert MapStuff
        //addAnnotations
       //MapStuff
        

        return cell2
    
    } else {
        //Standard-Labels with text
        let cell:ListPlacesTableViewCell = tableView.dequeueReusableCellWithIdentifier("listAllBakeries", forIndexPath: indexPath) as! ListPlacesTableViewCell
        cell.nameLabel?.text = namesBakeries[indexPath.row]
        cell.adressLabel?.text = "Test 2"
          return cell
    }    
}

感谢帮助

(对不起,我的英语不是我的母语)。

【问题讨论】:

  • 您无法更改行高,因为在情节提要中,地图视图不是单元格,而是标题,对吗?

标签: swift height mapkit tableview android-mapview


【解决方案1】:

看起来您的地图位于 uiTableView 上方,而不是表格中的单独原型单元格。

用 2 个原型单元格设置您的 uiTableView,然后将地图放在第一个单元格中。

然后,正如您所做的那样,您可以测试 indexpath.row 的值。

【讨论】:

    【解决方案2】:

    好吧,我知道了。

    诀窍是始终更新同一个单元格。 我定义了一个数组。然后将我的 Cell2 保存在这个数组中,并使用这个对象来更新我的地图。 (我知道我的英语很糟糕,也许我的代码会提供更多信息。)

    class ListPlacesTableViewController: UITableViewController {
    
    
    var constantCell = [ListPlacesTableViewCell?](count: 1, repeatedValue: nil)
    ....
    //other stuff here
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    
    if(indexPath.section == 0) {
            let cell2:ListPlacesTableViewCell = tableView.dequeueReusableCellWithIdentifier("MapCell", forIndexPath: indexPath) as! ListPlacesTableViewCell
    
            constantCell[0] = cell2
    //other stuff here
    }
    }
    //Clickable Cell Function add:
     constantCell[0]!.Map.setRegion(region, animated: true)
        constantCell[0]!.Map.addAnnotation(annotation)
    

    感谢您的帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-24
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-18
      相关资源
      最近更新 更多