gpt4 book ai didi

ios - 自定义扩展 UITableViewCell 有故障?

转载 作者:行者123 更新时间:2023-11-30 13:47:57 25 4
gpt4 key购买 nike

这是glitch 。正如您所看到的,当我将自定义 UITableViewCell SummaryCell 从应用程序 View 中推出时,单元格出现故障并且没有放置 UILabels dayOfTheWeektotalAmountSpent 放在适当的位置。但如果您单击有问题的单元格,它就会恢复正常。

以下是我用来创建自定义单元格 summaryCellUITableViewController SummaryTableViewController 的一些方法:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//Create day of week cell
let cell = tableView.dequeueReusableCellWithIdentifier("summaryCell", forIndexPath: indexPath) as! SummaryCell
let day = dayOfWeek[indexPath.row]

let height = CGFloat(55)
let dayOfWeekWidth = CGFloat(80)
cell.dayOfWeek.text = day.rawValue.uppercaseString
cell.dayOfWeek.frame = CGRectMake(0, 0, dayOfWeekWidth, height)
cell.dayOfWeek.backgroundColor = colorOfDay[day]

cell.totalAmountSpent.text = "$\(totalSpentPerDay[indexPath.row])"
cell.totalAmountSpent.frame = CGRectMake(cell.dayOfWeek.frame.maxX + 1, 0, view.bounds.width - dayOfWeekWidth, height)
cell.totalAmountSpent.backgroundColor = colorOfDay[day]
cell.totalAmountSpentView.backgroundColor = colorOfDay[day]

cell.heightOfMainView.constant = normalCellHeight
//^I have this to make sure the height of the cell is the same as
//the height of the mainView in the nib file `summaryCell` so that
//when the table loads intially, only the mainView of the `summaryCell` shows up.

return cell
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if expandedCellPaths.contains(indexPath){
let index = expandedCellPaths.indexOf(indexPath)
expandedCellPaths.removeAtIndex(index!)
}else{
expandedCellPaths.append(indexPath)
}

//old trick to animate cell expand/collapse
tableView.beginUpdates()
tableView.endUpdates()
}

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let expandedCellHeight = normalCellHeight*2
if expandedCellPaths.contains(indexPath){
return expandedCellHeight
}else{
return normalCellHeight
}
}

这是the nib file & its constraints对应于我的自定义 UITableViewCell SummaryCell

对于为什么会发生这种情况,我的 2 个最佳猜测是 (1) 我的 nib 文件 summaryCell 中的约束或(2)我的 UITableViewConroller SummaryTableViewController 中的行:

如果有人能告诉我如何修复这个故障,我将不胜感激! tableView.beginUpdates() tableView.endUpdates()

最佳答案

其实没关系!我意识到了我的错误!我只需要删除 tableView(:cellForRowAtIndexPath:) 中的这些行:

    let height = CGFloat(55)
let dayOfWeekWidth = CGFloat(80)
cell.dayOfWeek.frame = CGRectMake(0, 0, dayOfWeekWidth, height)
cell.totalAmountSpent.frame = CGRectMake(cell.dayOfWeek.frame.maxX + 1, 0, view.bounds.width - dayOfWeekWidth, height)

关于ios - 自定义扩展 UITableViewCell 有故障?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34690912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com