【发布时间】:2017-11-28 08:39:03
【问题描述】:
我想在函数内获取单元格(在 tableview 函数之外)。尝试这样,但是当它更改为第 1 行时,它崩溃了。
到目前为止,这是我的代码:
func ValueChecker(cell: UITableViewCell){
let subCellInt = Int(CustomUserDefaults.shared.getSubCellRow())!
let cell = self.tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as! BankPaymentDetailsCell
let mainMenuValue = CustomUserDefaults.shared.getSubCell()
if(mainMenuValue=="00" || mainMenuValue=="01" || mainMenuValue=="02" || mainMenuValue=="03" || mainMenuValue=="04" || mainMenuValue=="05" || mainMenuValue=="06"){
selectedRow = -1
cell.ivExpand.transform = CGAffineTransform(rotationAngle: (180.0 * CGFloat.pi) * 180.0)
}else{
cell.ivExpand.transform = CGAffineTransform(rotationAngle: (180.0 * CGFloat.pi) / 180.0)
}
tableView.beginUpdates()
tableView.endUpdates()
}
subCellInt 是我保存在本地的 indexpath.row。
如果我改成这样:
let cell = self.tableView.cellForRow(at: IndexPath(row: subCellInt, section: 0)) as! BankPaymentDetailsCell
它只对 0 号单元格(第一个单元格)有效,但在 1 号和 2 号单元格(对于 3 号单元格)时崩溃。
如何获取tableview函数外的单元格?
更新: 我使用此代码从外部 tableview 函数访问 tableview 单元格:
func ValueChecker(cell: UITableViewCell){
let subCellInt = Int(CustomUserDefaults.shared.getSubCellRow())!
let cell : BankPaymentDetailsCell = tableView.dequeueReusableCell(withIdentifier: "BankPaymentDetailsCell") as! BankPaymentDetailsCell
let mainMenuValue = CustomUserDefaults.shared.getSubCell()
if(mainMenuValue=="00" || mainMenuValue=="01" || mainMenuValue=="02" || mainMenuValue=="03" || mainMenuValue=="04" || mainMenuValue=="05" || mainMenuValue=="06"){
selectedRow = -1
cell.ivExpand.transform = CGAffineTransform(rotationAngle: (180.0 * CGFloat.pi) * 180.0)
}else{
cell.ivExpand.transform = CGAffineTransform(rotationAngle: (180.0 * CGFloat.pi) / 180.0)
}
tableView.beginUpdates()
tableView.endUpdates()
}
到目前为止,它有效。它可以从外部 tableview 函数访问单元格,并且不再崩溃。
【问题讨论】:
标签: uitableview swift3