ios – 如果行高度为UITableViewAutomaticDimension,则UITableViewWrapperView的大小不会随内容而改变

前端之家收集整理的这篇文章主要介绍了ios – 如果行高度为UITableViewAutomaticDimension,则UITableViewWrapperView的大小不会随内容而改变前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果行高为UITableViewAutomaticDimension,则UITableViewWrapperView的大小不会随内容而改变.

我正在尝试使用TableView和动态高度行创建Feed列表.
TableView是可滚动的,但UITableViewWrapperView看起来不会改变它的大小!

下面是视图层次结构的代码和截图.

我觉得很奇怪

码:

class FeedController: UITableViewController {

    var items: NSMutableArray = []

    override func viewDidLoad() {
        super.viewDidLoad()

        refreshControl?.addTarget(self,action: "FeedLoad",forControlEvents: UIControlEvents.ValueChanged)

        self.FeedLoad()

    }

    override func tableView(tableView: UITableView,estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 120.0
    }

    override func tableView(tableView: UITableView,heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        println("called")
        return UITableViewAutomaticDimension
    }

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

    override func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        return self.getCellForItemAtIndexPath( indexPath )
    }

    func getCellForItemAtIndexPath(indexPath: NSIndexPath) -> UITableViewCell {

        let item: Dictionary = self.items[indexPath.row] as Dictionary<String,AnyObject>

        let cell = tableView.dequeueReusableCellWithIdentifier( (item["type"] as String) + "Cell",forIndexPath: indexPath ) as FeedViewCell

        cell.fillData(item)

        return cell as UITableViewCell
    }

    func FeedLoaded(){

        tableView.reloadData()

    }

    func FeedLoad(){
        // Feed Load Logic which will call next line once Feed loaded

        self.FeedLoaded()
    }

}
@H_502_14@@R_404_323@
我假设你为你的单元格配置了自动布局,因为这是唯一的方式来使其工作.自动布局应该能够根据您的单元格限制来计算高度.

因此,您应该在垂直视图之间以及超视图(在这种情况下为单元格视图)的顶部和底部边缘的视图之间存在约束.

假设你有一个标题和描述的单元格,像这样:

|------------------|
| Title            |
|                  |
| Description with |
| long multiple    |
| lines of text    |
|------------------|

在这个例子中,你必须设置一个在标题和描述之间的垂直空间的约束,标题的顶部和单元格视图顶部之间的垂直空间的约束以及描述底部和单元格视图底部之间的垂直空间.

原文链接:https://www.f2er.com/iOS/329724.html

猜你在找的iOS相关文章