gpt4 book ai didi

ios - 在展开可选值访问 tableView Cell 时意外发现 nil

转载 作者:行者123 更新时间:2023-11-28 08:54:29 24 4
gpt4 key购买 nike

我想从外部 tableView func 访问 tableView 的单元格,例如,在这种情况下,我想从 IBAction Func 访问,然后我创建了 tableView 对象和 IndexPath 对象,当我运行我的项目时,Xcode 向我显示此错误:

Fatal error: unexpectedly found nil while unwrapping an Optional values

对于这一行:mytableView!.cellForRowAtIndexPath(indexPath!)

@IBAction func editButtonFunc(sender: AnyObject) {

mytableView!.cellForRowAtIndexPath(indexPath!)
let cell =
mytableView!.dequeueReusableCellWithIdentifier(
"mycell", forIndexPath: indexPath!)
as! profileTableViewCell
cell.contentOutlet.text = contentItems[indexPath!.row]
cell.contentOutlet.textAlignment = NSTextAlignment.Right
cell.contentOutlet.font = UIFont(name: "X Yekan", size: 18)

}

最佳答案

如果你只想获取某个单元格的引用,也许你需要:

func getTableViewCell() -> UITableViewCell? {
guard let tableView = mytableView, index = indexPath
else { return nil }

return tableView.cellForRowAtIndexPath(index)
}

而且,如果您想为 tableViewCell 设置数据,您应该在 UITableViewDataSource 方法中执行此操作:cellForRowAtIndexPath .

关于ios - 在展开可选值访问 tableView Cell 时意外发现 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33495199/

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