【问题标题】:perform Segue With Identifier from a dynamic collectionViewCell in a tableViewCell of a dynamic tableView, swift使用动态tableView的tableViewCell中的动态collectionViewCell执行Segue With Identifier,swift
【发布时间】:2016-05-11 23:44:16
【问题描述】:

我在一个动态tableView中,一个动态collectionView在其中一个tableViewCell中。

在每个 collectionViewCell 中,都有一个按钮应该是 segue 的触发器。

我尝试使用以下代码,但应用程序崩溃:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<Okm.bienController: 0x7fc8b0cfb1a0>) has no segue with identifier 'extend''

我的故事板中的转场标识符是“扩展”。

 class photoCell: UITableViewCell, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, UICollectionViewDataSource {
    ...

    func extendFunc(sender : UIButton) {

       bienController().performSegueWithIdentifier("extend", sender: sender.tag)
    }
}


class bienController : UIViewController, UITableViewDelegate, UITableViewDataSource {

...

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "extend" {
            let backItem = UIBarButtonItem()
            backItem.title = ""
            navigationItem.backBarButtonItem = backItem

            let extendView = segue.destinationViewController as! extendController
            extendView.image = image[sender]

        }
    }
}

你知道我该怎么做吗?

谢谢!!!

编辑

bienController().performSegueWithIdentifier(...) 这个词对吗?我可以从 UICollectionCell 调用我的控制器的函数吗?

编辑

我试过这个:

 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        if tableView == self.tableViewTwo {
            self.segue()
          // self.performSegueWithIdentifier("image", sender: nil)
        }
    }

    func clickExtend(sender:Int){
        print(sender) //print the correct tag!
       self.segue()
    }

    func segue(){
         self.performSegueWithIdentifier("image", sender: nil)
    }

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

        if segue.identifier == "image" {
            let backItem = UIBarButtonItem()
            backItem.title = ""
            navigationItem.backBarButtonItem = backItem
           // print(sender)

           let extendView = segue.destinationViewController as! extendController
           extendView.image = UIImage(named: "maison")

        }
    }
}

我将函数 clickExtend() 与我的 collectionCell 的按钮相关联。 当它来自 didSelectRowAtIndexPath 时,segue 工作,但是当我单击按钮扩展时,它崩溃并出现相同的错误:'由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'Receiver()没有标识符'image'的segue' '

我不明白..

(我更改了 'image' 的 segue 标识符)

【问题讨论】:

  • 你确定你已经在情节提要中将标识符设置为扩展了吗?四重检查
  • 是的,四重检查!我截图给你看!
  • 我尝试在另一个 tableviewcell 中添加一个带有 segue 标识符的按钮:“extend”,它可以工作..
  • bienController().performSegueWithIdentifier(...) 这个词对吗?我可以从 UICollectionCell 调用我的控制器的功能吗?

标签: swift uitableview uicollectionview segue


【解决方案1】:

检查 segue 是从单元格还是从 viewController 出来的。也许就是这样。

【讨论】:

  • 我尝试在另一个 tableviewcell 中添加一个带有 segue 标识符的按钮:“extend”,它可以工作..
  • bienController().performSegueWithIdentifier(...) 这个词对吗?我可以从 UICollectionCell 调用我的控制器的功能吗?
【解决方案2】:

看起来标识符要么没有正确连接,要么没有设置为“扩展”,因为错误消息说(没有与标识符“扩展”的序列)

【讨论】:

  • 我尝试在另一个 tableviewcell 中添加一个带有 segue 标识符的按钮:“extend”,它可以工作..
  • bienController().performSegueWithIdentifier(...) 这个词对吗?我可以从 UICollectionCell 调用我的控制器的功能吗?
  • 哦,也许您可​​以将新的 tableviewcell 设为最初的,也许这只是另一个 tableviewcell 的错误。祝你好运
  • bienController().performSegueWithIdentifier(...) 看起来不错。我是相当新的 ios 编程,所以我不确定调用函数。是的,试试费尔南多·卡尼的说法
【解决方案3】:

就像费尔南多·卡尼所说的

尝试更改bienController().performSegueWithIdentifier("name")

self.performSegueWithIdentifier("name")

【讨论】:

    【解决方案4】:

    您必须使用委托。我之前遇到过这个问题,我使用协议和委托来解决它并使用标识符执行一个segue。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-22
      • 1970-01-01
      • 2019-04-07
      相关资源
      最近更新 更多