【发布时间】: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