gpt4 book ai didi

ios - 无法将 TableViewCell 类型的值转换为 'NSIndexPath'

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

无法将“Google_Books_1.BookTableViewCell”类型的值 (0x105557600) 转换为“NSIndexPath”(0x1061cb438)

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("BookCell", forIndexPath: indexPath) as!BookTableViewCell
...
}


func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
// let contact = ContactList![indexPath.row]
performSegueWithIdentifier("BookDetailSegue", sender: indexPath)
}
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
// let contact = ContactList![indexPath.row]
performSegueWithIdentifier("BookDetailSegue", sender: indexPath)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "BookDetailSegue" {
let vc = segue.destinationViewController as! BookDetailViewController

let indexPath = sender as! NSIndexPath
vc.book = self.bookList[indexPath.row] **//error is here**
vc.index = indexPath.row
}
}

如何处理此类错误?

最佳答案

为什么不以 tableView 的 indexPathForSelectedRow 属性为基础呢?

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "BookDetailSegue" {
let vc = segue.destinationViewController as! BookDetailViewController
if let indexPath = tableView.indexPathForSelectedRow {
vc.book = self.bookList[indexPath.row] **//error is here**
vc.index = indexPath.row
}
}
}

关于ios - 无法将 TableViewCell 类型的值转换为 'NSIndexPath',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37772739/

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