[英]segue from UIViewController to UITableViewController
I'm trying to segue
data from UIViewController
to UITableViewController
. 我想
segue
数据从UIViewController
到UITableViewController
。 The data in UIViewController
is coming from PFTableViewController
and I want to pass that data to another TableViewController
. UIViewController
的数据来自PFTableViewController
,我想将该数据传递给另一个TableViewController
。
For passing to ViewController didSelect
method is used but I have no idea how can I segue from viewController
to TableViewController
. 为了传递给ViewController使用了
didSelect
方法,但我不知道如何从viewController
到TableViewController
。
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let destinationToFVC:ViewController = self.storyboard!.instantiateViewControllerWithIdentifier("FVCont") as! ViewController
if let indexPath = self.tableView.indexPathForSelectedRow {
let row1 = Int(indexPath.row)
destinationToFVC.currentObject = objects?[row1] as! PFObject!
}
navigationController?.pushViewController(destinationToFVC, animated: true)
}
I'm new to programming. 我是编程新手。
In your case you can launch the segue manually from your didSelectRowAtIndexPath
, with the the method performSegueWithIdentifier
. 你的情况,你可以从你的手动启动SEGUE
didSelectRowAtIndexPath
,用该方法performSegueWithIdentifier
。
You need to create a custom segue in your Storyboard from your UIViewController
to your UITableViewController
and set an Identifier
for it, you can press Ctrl
+ Click
from your UIViewController
to the next to create the custom segue and then select the segue and in the Attributes Inspector set the Identifier for the segue just a this picture: 您需要在Storyboard中从
UIViewController
到UITableViewController
创建自定义序列,并为其设置一个Identifier
,您可以按Ctrl
+从UIViewController
到下一个Click
以创建自定义序列,然后选择该序列并在Attributes Inspector中只需为这张图片设置segue的标识符:
Then you can in your didSelectRowAtIndexPath
launch the segue manually as in this code: 然后,您可以按照以下代码在
didSelectRowAtIndexPath
手动启动segue:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// the identifier of the segue is the same you set in the Attributes Inspector
self.performSegueWithIdentifier("mySegueID", sender: self)
}
And of course you need to implement the method prepareForSegue
to pass the data from your UIViewController
to your UITableView
like in this code: 当然,您需要实现方法
prepareForSegue
以将数据从UIViewController
传递到UITableView
如以下代码所示:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "mySegueID") {
// in this line you need to set the name of the class of your `UITableViewController`
let viewController = segue.destinationViewController as UITableViewController
let indexPath = self.tableView.indexPathForSelectedRow()
destinationToFVC.currentObject = objects?[indexPath] as! PFObject!
}
}
EDIT:
编辑:
If you want to perform your segue from an UIButton
to the UITableViewController
it's the same logic, just create the custom segue in your Storyboard and then call the prepareForSegue
like in the following code: 如果要从
UIButton
到UITableViewController
执行序列化,这是相同的逻辑,只需在Storyboard中创建自定义序列化,然后像下面的代码中那样调用prepareForSegue
:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "mySegueID") {
// in this line you need to set the name of the class of your `UITableViewController`
let viewController = segue.destinationViewController as UITableViewController
/ here you need to pass the data using the reference viewController
}
}
I hope this help you. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.