作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有原型(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/
我有一个自定义的表格 View 单元格,前面有一个图像,中间有几个标签,最后有一个图像。当画外音打开并聚焦于整个 tableview 行时,所有标签都被读取,然后当我滑动以移动到下一个控件时,第一个图
我有原型(prototype)单元,在这个单元中有一个 UIButton;所以我需要执行从按钮到其他 Controller 的连接,而不是从单元格的连接。我尝试创建一个 Outlet @IBOutle
我是一名优秀的程序员,十分优秀!