gpt4 book ai didi

ios - 使用 CABasicAnimation 在 tableView 中崩溃,当 UITableViewCell 不可见时文本颜色

转载 作者:行者123 更新时间:2023-11-29 00:25:25 25 4
gpt4 key购买 nike

该应用程序是一个满意度调查,所有字段都必须由人填写。我使用了一个 tableView,我希望,当一个字段未填充时,它会自动滚动到该字段,将 tableviewcell 设置为红色,并摇动 tableviewcell。我找到了所有这些,但问题是当单元格不在屏幕上时它似乎崩溃了(可能是因为单元格在屏幕上不可见)。

可能我必须做一些事情来等待单元格首先可见。我该怎么做?

    let cellPb = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: 1, inSection: 0))

self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Top, animated: false)
//color
cellPb!.textLabel!.textColor = UIColor.redColor()

//shake the cell
let shake = CABasicAnimation(keyPath: "position")
shake.duration = 0.1
shake.repeatCount = 3
shake.autoreverses = true
shake.fromValue = NSValue(CGPoint: CGPointMake(cellPb!.center.x - 5, cellPb!.center.y))
shake.toValue = NSValue(CGPoint: CGPointMake(cellPb!.center.x + 5, cellPb!.center.y))
cellPb!.layer.addAnimation(shake, forKey: "position")

UIAlertView(title: "Please, fill the blank field.", message: nil, delegate: nil, cancelButtonTitle: "Ok").show()

最佳答案

尝试反过来,先滚动然后获取单元格:

let indexPath = NSIndexPath(forRow: 1, inSection: 0)
self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Top, animated: false)
let cellPb = self.tableView.cellForRowAtIndexPath(indexPath)

关于ios - 使用 CABasicAnimation 在 tableView 中崩溃,当 UITableViewCell 不可见时文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43157034/

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