ios - 如何在 swift 中设置 tableview Accordion ?

标签 ios swift accordion

我是 IOS 新手,试图设计一个 Accordion 菜单。我被卡住了。首先,我让我的 UI 具有一些静态内容( TableView 和 View 中的 3 行标签......)。在尝试设置 Accordion 时。 .没有显示任何回应..

这里是我的 viewcontroller.swift

 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
    let previndexPath = selectedIndexPath
    if indexPath == selectedIndexPath
    {
        selectedIndexPath = nil
    }
   else
    {
        selectedIndexPath = indexPath
    }

    var indexPaths:Array <NSIndexPath> = []
    if let previous = previndexPath
    {
        indexPaths += [previous]
    }
    if let current = selectedIndexPath
    {
        indexPaths += [current]
    }
    if indexPaths.count > 0
    {
        tableView.reloadRowsAtIndexPaths(indexPaths, withRowAnimation:UITableViewRowAnimation.Automatic)
    }

}


func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

    (cell as! TableViewCell).watchFrameChanges()
    (cell as! TableViewCell2).watchFrameChanges()
}

 func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)
 {
    (cell as!TableViewCell).ignoreFrameChanges()
    (cell as!TableViewCell2).ignoreFrameChanges()
}
override func viewWillDisappear(animated: Bool)
{
    super.viewWillDisappear(animated)
    for cell in tblvw.visibleCells as! [TableViewCell] {
        cell.ignoreFrameChanges()
    }
   for cell in tblvw.visibleCells as! [TableViewCell2] {
            cell.ignoreFrameChanges()
    }
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if indexPath == selectedIndexPath {
        return TableViewCell.expandedHeight

    } else {
       return TableViewCell.defaultHeight

 }


    if indexPath == selectedIndexPath {
        return TableViewCell2.expandedHeight
   } else {
       return TableViewCell2.defaultHeight
    }
   return 0.0

}

最佳答案

我也有同样的问题。问题是何时实现多个单元。解决办法是:

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)


    for cell in tableView.visibleCells {

        if(cell.reuseIdentifier == "YOUR_IDENTIFIER_FROM_CELL")
        {
            let ncelda = cell as! TableViewCell
            ncelda.ignoreFrameChanges()
        }

        else
        {
            let mcelda = cell as! TableViewCell2
            mcelda.ignoreFrameChanges()
        }
    }
}

关于ios - 如何在 swift 中设置 tableview Accordion ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35837736/

相关文章:

ios - MvvmCross Xamarin.Forms(iOS): Using a TabbedPage within a MasterDetail page

javascript - 平滑网格折叠时 resizeCanvas 不起作用

ios - 有效地更新 UITabelView 单元格

ios - .h 中的静态 const 定义与 .m 中的外部 const 定义

使用 Storyboard的 Xcode 6.1 OSX 应用程序不呈现窗口或菜单栏

ios - View 如何更新 View Controller ?

javascript - 在页面上使用 jQuery UI 控件的多个实例时出现问题。 Accordion 控件的多种用途

jQuery Accordion - 需要当前所选内容部分的索引

ios - `ExpressibleByArrayLiteral`符合类及其父类(super class)=> “<superclass> is not convertible to <subclass>”

ios - 如何从 UIImagePickerController 获取授权的 PHAsset?