gpt4 book ai didi

ios - 无法将类型 'NeuroCongress.celulaTableViewCell' (0x15836c) 的值转换为“NeuroCongress.Evento”

转载 作者:可可西里 更新时间:2023-11-01 02:15:27 25 4
gpt4 key购买 nike

当我将对象传递给 segue 时,出现此错误:

Could not cast value of type 'NeuroCongress.celulaTableViewCell' (0x15836c) to 'NeuroCongress.Evento'

//---------------- newTableViewController --------------------

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! celulaTableViewCell


cell.titLabel?.text = evento[indexPath.row].titulo
cell.subTitLabel?.text = evento[indexPath.row].localizacao

return cell

}


func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// cria evento com o selecionado atual
let evento = self.evento[indexPath.row]
// envia evento criado acima como sender para o segue detailSegue
self.performSegueWithIdentifier("detailSegue", sender: evento)


}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

let detailVC = segue.destinationViewController as! DetailViewController
// envia objeto que veio via sender do didselectrow como objeto Friend para a VC FriendDetail
detailVC.eventozinho = sender as! Evento


}

//----------------- DetailViewController --------------------

import UIKit

class DetailViewController: UIViewController {

@IBOutlet weak var lblTitulo: UILabel!
@IBOutlet weak var lblInicio: UILabel!
@IBOutlet weak var lblFim: UILabel!
@IBOutlet weak var lblLocal: UILabel!
@IBOutlet weak var lblPais: UILabel!
@IBOutlet weak var lblContato: UILabel!
@IBOutlet weak var lblAssunto: UILabel!

@IBOutlet weak var lblWeb: UILabel!
@IBAction func btnAbrir(sender: AnyObject) {

openWebPage(self.eventozinho.website)

}

var eventozinho = Evento()



override func viewDidLoad() {
super.viewDidLoad()

self.lblTitulo.text = self.eventozinho.titulo

self.lblInicio.text = String(self.eventozinho.dtinicio!)
self.lblFim.text = String(self.eventozinho.dttermino!)

self.lblLocal.text = self.eventozinho.localizacao
self.lblPais.text = self.eventozinho.pais

self.lblWeb.text = self.eventozinho.website

self.lblAssunto.text = self.eventozinho.assunto
self.lblContato.text = self.eventozinho.contato

最佳答案

我怀疑您通过从 TableView 单元格原型(prototype)拖动到 DetailViewController 来在 Storyboard中创建了 segue。因此,当您点击单元格时会自动触发 segue - 在本例中,sender 参数是被点击的单元格。因此出现错误:您的 prepareForSegue 假定发送者参数是 Event,但它实际上是单元格。如果您以这种方式设置 segue,则无需使用 didSelectRowAtIndexPath 来触发 segue。事实上,prepareForSegue 在 didSelectRowAtIndexPath 方法被调用之前运行。您可以修改 prepareForSegue 以使用 indexPathForCell(传递 sender - 您可能需要正确转换它)来确定正确的 indexPath(因此将哪个事件传递给目标 View Controller )。

或者,在您的 Storyboard中删除 segue 并通过从 View Controller 本身(使用场景顶部的图标)拖动到 DetailViewController 来重新创建它。在这种情况下,您当前的代码应该可以工作 - didSelectRowAtIndexPath 代码将运行并触发 segue,将事件作为发送者传递。

关于ios - 无法将类型 'NeuroCongress.celulaTableViewCell' (0x15836c) 的值转换为“NeuroCongress.Evento”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39102273/

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