从Custom Cell UIButton创建Segue到ViewController

时间:2014-09-09 15:53:36

标签: uiviewcontroller swift uibutton custom-cell xcode6-beta5

我想从(a)UIButton(在tableview的自定义单元格中)和(b)一般自定义单元格到UIViewController创建一个segue。自定义单元格在.xib文件中指定。我读到我应该控制从UIButton /自定义单元格到UIViewController的拖动。这对我没用。

  1. 自定义单元格的.xib文件不在故事板内 - 这是对的吗? 我想到它应该在故事板里面。如有必要,我该怎么做?
  2. 如何从UIButton(在自定义单元格中)/自定义单元格中创建一个segue到UIViewController?
  3. 谢谢!

    编辑:我使用UITableViewController作为Source,目标是带有UITableView的UIViewController。

2 个答案:

答案 0 :(得分:0)

从tableViewController(而不是从原型单元格)按住Ctrl键拖动到目标viewController,并为segue指定一个标识符名称。

现在覆盖didSelectRowAtIndexPath以在点击该单元格时使用您的标识符执行segue:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)    
{
    performSegueWithIdentifier("yourSegue", sender: nil)
}

根据indexPath区分单元格,并根据需要为目标viewControllers创建尽可能多的segue。

您可以对自定义单元格中的按钮执行类似操作。在按钮的动作上执行segue。

答案 1 :(得分:0)

我使用xcode6beta5应该是问题所在。现在我正在使用xCode6 GM,并且像zisoft写的那样创建segues非常好!谢啦!!