Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法强制转换类型为';NeuroCongress.celulaTableViewCell';(0x15836c)至';神经会议_Ios_Swift_Uitableview_Uiviewcontroller - Fatal编程技术网

Ios 无法强制转换类型为';NeuroCongress.celulaTableViewCell';(0x15836c)至';神经会议

Ios 无法强制转换类型为';NeuroCongress.celulaTableViewCell';(0x15836c)至';神经会议,ios,swift,uitableview,uiviewcontroller,Ios,Swift,Uitableview,Uiviewcontroller,当我将对象传递给segue时,我得到以下错误: 无法将“NeuroCongress.celulaTableViewCell”(0x15836c)类型的值强制转换为“NeuroCongress.Evento” //------------------newTableViewController-------------------- func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPat

当我将对象传递给segue时,我得到以下错误:

无法将“NeuroCongress.celulaTableViewCell”(0x15836c)类型的值强制转换为“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


    }
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
//------------------详细视图控制器--------------------

 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


    }
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

我怀疑您已经通过从表视图单元原型拖动到DetailViewController在情节提要中创建了segue。因此,点击单元格时会自动触发segue,在本例中,
sender
参数就是点击的单元格。因此出现了错误:prepareForSegue假设发送方参数是
事件
,但它实际上是单元格。如果以这种方式设置segue,则无需使用
didSelectRowAtIndexPath
触发segue。事实上,prepareForSegue在调用
didselectrowatinexpath
方法之前运行。您可以修改
prepareForSegue
以使用
indexPathForCell
(传递
sender
-您可能需要正确地强制转换它)来确定正确的indexPath(以及传递给目标视图控制器的事件)


或者,在情节提要中,删除片段并通过将其从视图控制器本身(使用场景顶部的图标)拖动到DetailViewController重新创建。在这种情况下,您当前的代码应该可以工作,
didSelectRowAtIndexPath
代码将运行并触发segue,将事件作为发送者传递。

谢谢,您就是那个人。