gpt4 book ai didi

swift - 从 TabeViewCell 中的 UIButton 触发 Segue

转载 作者:行者123 更新时间:2023-11-30 14:06:33 24 4
gpt4 key购买 nike

我有原型(prototype)单元,在这个单元中有一个 UIButton;所以我需要执行从按钮到其他 Controller 的连接,而不是从单元格的连接。我尝试创建一个 Outlet @IBOutlet var button: UIButton! 并使用 PerformSegueWithIdentifier() 方法

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
self.performSegueWithIdentifier("toSecondController", sender: button)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}

但我不知道如何设置prepareForSegue()方法...我尝试了这个

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if segue.identifier == "toSecondController"
{
if let indexPath = sender as? UIButton//tableView.indexPathForSelectedRow()
{
let controller = segue.destinationViewController as! CoriViewController
controller.coriSquadra = DataManager.sharedInstance.arrayCori[indexPath.row]
}
}
}

我还读到解决方案是实现一个协议(protocol),但我是初学者,我需要一步一步的指南。希望有人能帮助我!

最佳答案

你走在正确的道路上。在你的tableviewcontroller中定义

@IBAction func clicked(){
self.performSegueWithIdentifier("toSecondController", sender: button)
}

您可以保留

    tableView.deselectRowAtIndexPath(indexPath, animated: true)

didSelectRowAtIndexPath 中的行。不要忘记将您的 ibaction 也连接到 Storyboard中的按钮。

关于swift - 从 TabeViewCell 中的 UIButton 触发 Segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32320558/

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