- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个填充了数据的 tableView,当点击该行时我的所有单元格当前都可以展开/折叠。
但是,我的 UITableView 中的最后一个单元格是一种不同类型的数据,点击时不应展开。
我已将其设置为一次只能展开一个单元格,因此如果当前正在展开另一个单元格并且他们点击 UITableView 中的最后一个单元格,该单元格仍应折叠,但最后一个单元格不应展开.
我检查它是否是最后一个不应展开的单元格的方法是检查其中一个标签:if cell.tickerLabel.text == " CASH"
我可以验证它是正确的,并且 if 语句对最后一个单元格运行。
我已经尝试了很多不同的实现,将 if 语句插入到我展开和折叠单元格的代码中。但我尝试过的都没有达到预期效果。
下面是我的展开/折叠单元格的代码:
我的 didSelectRowAtIndexPath 函数 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 让 cell = tableView.dequeueReusableCellWithIdentifier("com.Stocks.portfolioCell", forIndexPath: indexPath) 作为!投资组合单元格
if let selectedCellIndexPath = selectedCellIndexPath {
if selectedCellIndexPath == indexPath {
self.selectedCellIndexPath = nil
currentCollapsing = true
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .None)
} else {
lastCollapsing = true
self.selectedCellIndexPath = indexPath
tableView.reloadRowsAtIndexPaths([lastIndexPath], withRowAnimation: .None)
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .None)
self.lastIndexPath = indexPath
}
} else {
selectedCellIndexPath = indexPath
self.lastIndexPath = indexPath
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None)
}
tableView.beginUpdates()
tableView.endUpdates()
}
我的 heightForRowAtIndexPath 函数
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let SelectedCellHeight: CGFloat = 210
let UnselectedCellHeight: CGFloat = 50
if let selectedCellIndexPath = selectedCellIndexPath {
if selectedCellIndexPath == indexPath {
return SelectedCellHeight
}
}
return UnselectedCellHeight
}
最后是我的 cellForRowAtIndePath 函数中与这个问题相关的部分:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("com.Stocks.portfolioCell", forIndexPath: indexPath) as! portfolioCell
cell.heightSeperator.hidden = true
cell.stockNameView.hidden = true
cell.purchasePriceView.hidden = true
cell.lastPriceView.hidden = true
cell.daysHeldView.hidden = true
cell.endSeperator.hidden = true
if indexPath.row % 2 == 0 {
cell.backgroundColor = UIColor.formulaWhiteColor()
} else {
cell.backgroundColor = UIColor.whiteColor()
}
if selectedCellIndexPath == indexPath {
cell.tickerLabel.textColor = UIColor.formulaBlueColor()
cell.heightSeperator.hidden = false
cell.stockNameView.hidden = false
cell.purchasePriceView.hidden = false
cell.lastPriceView.hidden = false
cell.daysHeldView.hidden = false
cell.endSeperator.hidden = false
tableHeight.constant = tableHeight.constant+210
self.scrollView.contentSize = CGSize(width:self.view.bounds.width, height: self.contentView.frame.height)
self.view.setNeedsDisplay()
}
if lastCollapsing == true || currentCollapsing == true {
lastCollapsing = false
currentCollapsing = false
tableHeight.constant = tableHeight.constant-210
self.scrollView.contentSize = CGSize(width:self.view.bounds.width, height: self.contentView.frame.height)
self.view.setNeedsDisplay()
}
}
任何人都可以帮助我指出正确的方向,让我知道如何制作它,以便我的最后一个单元格不可扩展,同时仍然允许任何其他打开的单元格在点击它时折叠吗?
如有任何帮助,我们将不胜感激!
最佳答案
您应该检查 indexPath 是否是 heightForRow
中的最后一个。
由于您可以选择最后一行,因此逻辑将确定最后一行已被选中,并且在计算它的高度时,它会像被选中一样进行计算(确实如此)。因此,您应该通过在 heightForRow
委托(delegate)方法中处理它来避免扩展最后一行。
更新
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let SelectedCellHeight: CGFloat = 210
let UnselectedCellHeight: CGFloat = 50
//Add this here, where numberOfRows is self explanatory
//So replace it with the actually variable.
if indexPath.row == numberOfRows - 1 {
return UnselectedCellHeight;
}
if let selectedCellIndexPath = selectedCellIndexPath {
if selectedCellIndexPath == indexPath {
return SelectedCellHeight
}
}
return UnselectedCellHeight
}
关于ios - Swift 允许扩展除一个以外的所有单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30581927/
我已经坚持了好几天了……很抱歉遇到这样的问题,但是我只是F#本身的初学者。由于关于类型提供程序的讨论很多,所以我决定建立一个类型提供程序并撰写一篇有关它的论文。当我开始时,我不知道什么是类型提供程序。
我正在开发LAN项目唤醒功能,但是我想控制局域网中计算机是否打开。但是我不想使用ICMP或WMI(我的网络上有DC)。那么,对于此问题,是否还有其他选择,例如“套接字连接”,请检查特定端口是否正在使用
我们有一个旧的VB6应用程序,该应用程序使用Crystal Reports XI生成打印报告。我们已经通过经验发现,如果Crystal Reports打印引擎选择了错误版本的 usp10.dll (W
我正在尝试获取有效的 Android 权限列表。我知道 http://developer.android.com/reference/android/Manifest.permission.html
嗨,我是 nginx 的新手,我试图在我的服务器(运行 Ubuntu 4)上设置它,它已经运行了 apache。 所以在我 apt-get install 它之后,我尝试启动 nginx。然后我收到这
如何在VB 6中检查对象的类型-除了'TypeName'之外,是否还有其他方法,因为无法通过'TypeName'进行检查,我希望使用类似QuichWatch窗口的方法。 最佳答案 对于对象变量,请使用
我的 JSP 应用程序中有一个错误。发布后我的 session 被清除: YAHOO.util.Connect.asyncRequest('POST', Url, callback, post
我是一名优秀的程序员,十分优秀!