Swift - 更改tableView内mapview的高度

标签 swift height mapkit tableview android-mapview

(查看##编辑##) 我是初学者。我使用了 google,但找不到解决我的问题的方法。

如何更改 tableView 内 MapView 的高度?

我的 Storyboard看起来像: 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是第一个条目“Name: Test”

有人可以解释一下我无法更改尺寸的方式和原因吗?如何更改大小?

谢谢你的帮助。

编辑

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

当我单击某个条目时,“ map 单元格”上没有更新,但“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
    }    
}

感谢帮助

(我对我的英语感到抱歉,但这不是我的母语)。

最佳答案

看起来您的 map 位于 uiTableView 上方,而不是表格中单独的原型(prototype)单元格。

使用 2 个原型(prototype)单元设置您的 uiTableView,然后将 map 放在第一个单元中。

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

关于Swift - 更改tableView内mapview的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32447743/

相关文章:

ios - mapKit 不显示注释

ios - 你如何使用“let newSwiftColor = UIColor(red : 255, green : 165, blue : 0, alpha : 0)?

html - Bootstrap 3 Column Site {高度 : 100%;} not working

css - 如何使用嵌入使 Bootstrap 4 中的列高相等?

css - 样式化的 div 以零高度呈现

iphone - 在 iOS map 中搜索附近

ios - GameCenter 与 SpriteKit 集成

ios - 检索我们处于生命周期 Controller 的哪个状态

ios - 无法在 ScrollView 上选择选项卡栏中的项目

iOS MapKit - 检测 map 何时完全放大?