0
我是IOS新手,試圖設計一個手風琴menu.i得到了stucked ..首先我讓我的UI有一些靜態內容(在表格視圖和視圖中有3行標籤..)。沒有顯示任何反應..如何在swift中設置tableview手風琴?
這裏我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
}