更改UITableViewCell高度在内部进行修饰 [英] Change UITableViewCell height touch up inside

查看:88
本文介绍了更改UITableViewCell高度在内部进行修饰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我想让我的单元格动态改变高度。我会尽我所能。当我在一个单元格(原型单元格)内触摸时,该单元格的高度会从44变为88;在该单元格中,有一个UIImage(88px高度)被部分隐藏,并且在该单元格隐藏的地方有视图,触摸起来会开始搜索到另一个tableView;当我在另一个单元格中触摸时,前一个单元格返回到44px的高度,另一个单元格的高度与前一个单元格一样。遵循我需要做的计划。

As the title says, I'd like to make my cells dynamically change height. I try to be as clear that I can. When I touch up inside a cell (prototype cell), the cell change height (from 44 to 88);in the cell there is an UIImage (88px height) partially hidden and where the cell is hidden there is view, touching up starts a segue to a second tableView; when I touch up inside an other cell the previous cell return to 44px height an this other cell change height as the previous one. Follow a scheme of I need to do.

我认为这非常很难,所以如果有人可以帮助我执行此功能,我将不胜感激!或者,如果您知道任何获得想法的示例(例如gitHub),请报告我!
非常感谢:-)

I think that this is quite difficult, so If someone could help me doing this feature I would be very grateful!! or if you know any examples to get ideas (by gitHub for example) please report me! thanks a lot :-)

推荐答案

还不错。我是这样做的,可能会有更聪明的方法来做。
重要的东西是tableView.beginUpdate和.... endUpdate。

It is not so bad. I have done it like this, there might be smarter ways to do it. The important stuff is tableView.beginUpdate and ....endUpdate.

  //
    //  DynamicTableViewController.swift
    //  DynamicCellTest
    //
    //  Created by Lars Christoffersen on 27/08/15.
    //  Copyright (c) 2015 Lars Christoffersen. All rights reserved.
    //

    import UIKit

    class DynamicTableViewController: UITableViewController {

        var dataCource = ["A","B","C","D","E","F","G","H"]
        var extraHeight:CGFloat?
        var selectedRowIndex:Int?

        override func viewDidLoad() {
            super.viewDidLoad()
        }

        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
        }

        override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {


            if extraHeight != nil && selectedRowIndex != nil && selectedRowIndex == indexPath.row{
                return 41 + extraHeight!
            }else{
                return 41
            }
        }


        override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
            self.tableView.beginUpdates()
            selectedRowIndex = indexPath.row
            extraHeight = 100
            self.tableView.endUpdates()

        }

        override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
            self.tableView.beginUpdates()
            selectedRowIndex = indexPath.row
            extraHeight = 0
            self.tableView.endUpdates()
        }

        override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
            return 1
        }

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


        override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell

            cell.textLabel?.text = dataCource[indexPath.row]
            return cell
        }
    }

这篇关于更改UITableViewCell高度在内部进行修饰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆