UITableView内容大小不为';在ios7中更新

UITableView内容大小不为';在ios7中更新,ios,uitableview,ios7,uiview,scrollview,Ios,Uitableview,Ios7,Uiview,Scrollview,我有一个UITableViewController,它通常使用datasource委托方法加载一些单元格 在ios8中,一切正常,但在ios7中,contentsize的高度似乎与单元格的高度不符 它正确地添加了屏幕底部的单元格,当我想向下滚动时,它不会滚动,它只是启动反弹动画,就像你在底部一样。当我拖动时,我可以看到屏幕底部的单元格,但当我松开它时,它会反弹回来 我想这只是我丢失的一些财产,但我似乎找不到哪一个 我根本没有配置表视图,我只是使用数据源将单元格添加到其中 编辑 我正在使用自动布局

我有一个UITableViewController,它通常使用datasource委托方法加载一些单元格

在ios8中,一切正常,但在ios7中,contentsize的高度似乎与单元格的高度不符

它正确地添加了屏幕底部的单元格,当我想向下滚动时,它不会滚动,它只是启动反弹动画,就像你在底部一样。当我拖动时,我可以看到屏幕底部的单元格,但当我松开它时,它会反弹回来

我想这只是我丢失的一些财产,但我似乎找不到哪一个

我根本没有配置表视图,我只是使用数据源将单元格添加到其中

编辑

我正在使用自动布局

当我打印出contentsize时,它会打印出CGSizeZero

var BookingInfo:[[String:AnyObject]]? { didSet { self.tableView.reloadData() } }

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return BookingInfo == nil ? 0 : BookingInfo!.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let bookingInfo = BookingInfo![indexPath.row]
    let id = (bookingInfo["id"] as Int).toString()

    var cell = tableView.dequeueReusableCellWithIdentifier(id) as? ListCell
    if cell == nil { cell = ListCell(bookingInfo: bookingInfo, reuseID: id) }
    return cell!
}
BookingInfo在该视图之前的另一个视图中的prepareSegue函数中设置

ListCell是一个自定义单元格,它使用BookingInfo中的坐标加载地图

我正在更改单元格ID,以便在排序时快速访问,这样地图就不必重新加载

编辑2

我在用地图盒

class ListCell:UITableViewCell, RMMapViewDelegate {
    var BookingInfo:[String:AnyObject]!
    var mapView:RMStaticMapView!



    func mapView(mapView: RMMapView!, layerForAnnotation annotation: RMAnnotation!) -> RMMapLayer! {
        let marker = RMMarker(UIImage: UIImage(named: "MapPin.png")!.scaledImage(0.66))
        marker.anchorPoint = CGPoint(x: 0.5, y: 1)
        annotation.layer = marker
        marker.canShowCallout = false

        return marker
    }

    func setup(frame: CGRect) {
    self.backgroundColor = nil

        let mapFrame = CGRect(x: 0, y: 0, width: frame.height, height: frame.height)
        if mapView == nil {
        self.mapView = RMStaticMapView(frame: mapFrame, mapID: "an ID")

            if self.mapView != nil {
                self.mapView!.delegate = self
                self.mapView!.showLogoBug = false

                self.mapView!.setZoom(11, atCoordinate: CLLocationCoordinate2D(latitude: (self.BookingInfo["lat"] as String).toDouble(), longitude: (self.BookingInfo["lon"] as String).toDouble()), animated: false)
                self.mapView!.addAnnotation(RMAnnotation(mapView: self.mapView, coordinate: self.mapView!.centerCoordinate, andTitle: ""))
                self.contentView.addSubview(self.mapView!)
            }
        }
    }
    override func layoutSubviews() {
        gcd.async(.Main) {
            self.setup(self.bounds)
        }

        super.layoutSubviews()
    }
    convenience init(bookingInfo: [String:AnyObject], reuseID: String) {
        self.init(style: .Default, reuseIdentifier: reuseID)
        self.BookingInfo = bookingInfo
    }
}
这个类中有更多的内容,但它们与地图没有任何关系,它们只是简单的UILabel,删除了它们,所以不会太长

在@ROB的回答后编辑

我添加了约束,但contentSize仍然变为{0,0}

// In viewDidLoad
self.tableView.rowHeight = 100   

// In ListCell.setup:
self.mapView = RMStaticMapView(frame: mapFrame, mapID: "an ID")
self.mapView.setTranslatesAutoresizingMaskIntoConstraints(false)    
self.contentView.addSubview(self.mapView!)

var arr = NSLayoutConstraint.constraintsWithVisualFormat("|[mapView]", options: nil, metrics: nil, views: ["mapView":self.mapView])
arr += NSLayoutConstraint.constraintsWithVisualFormat("V:|[mapView]|", options: nil, metrics: nil, views: ["mapView":self.mapView])
self.contentView.addConstraints(arr)

let constraintRatio = NSLayoutConstraint(item: self.mapView, attribute: .Width, relatedBy: .Equal, toItem: self.mapView, attribute: .Height, multiplier: 1, constant: 0)

self.mapView.addConstraint(constraintRatio)

现在,您似乎正在将地图视图的边框设置为与单元格的边界相同。相反,我将为地图视图定义具有相同基本功能的约束:

let mapView = MKMapView()
mapView.userInteractionEnabled = false
mapView.setTranslatesAutoresizingMaskIntoConstraints(false)
contentView.addSubview(mapView)

let views = ["mapView" : mapView]
contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[mapView]|", options: nil, metrics: nil, views: views))
contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[mapView]|", options: nil, metrics: nil, views: views))
当我配置它时(加上设置tableView的
行高
),它在iOS 7和iOS 8中都表现良好


如果您有可变或动态单元格高度,则过程会略有不同。iOS 8比iOS 7更优雅地处理这类事情。

@Rob I更新了question@Rob它是一个UITableViewController,因此tableview的框架将覆盖整个屏幕。问题是,我不认为它与我的代码有什么关系,我认为它是一个ios7行为,会把事情搞砸。我删除了地图,然后它工作得很好。。。这真的很奇怪,只是在ios7中搞砸了。我将更新如何将映射添加到ListCell。@Rob如果我删除将映射添加到contentView的行,它将按照其假定的方式工作。。。我在一个dispatch_中添加了它,5秒后它添加了地图,一旦添加,tableView contentSize就会变成CGSizeZero。。。我现在很困惑,不知道该怎么办。我将地图大小设置为cellHeight,cellHeight,所以我将添加一些约束条件,看看它是否有效。