如何使用 didSelectRowAtIndexPath(在 Swift 中)在两个 Storyboard 之间传递日期? [英] How to passing Date between two Storyboard with didSelectRowAtIndexPath(in Swift)?
本文介绍了如何使用 didSelectRowAtIndexPath(在 Swift 中)在两个 Storyboard 之间传递日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用 didSelectRowAtIndexPath
来传递搜索后我当前的单元格(这是我找到的唯一方法),但是如何将这个单元格名称传递给 SecondViewController?
I need to use didSelectRowAtIndexPath
to pass
my current Cell after Searching (this is the only way that I found),
but how can I pass this cell name to the SecondViewController?
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if(tableView == self.searchDisplayController!.searchResultsTableView){
if let cell: UITableViewCell = tableView.cellForRowAtIndexPath(indexPath){
if let cellTextLabel: UILabel = cell.textLabel{
let cellSelected = cellTextLabel.text!
}
}
}
在 SecondViewController 中,我需要使用 TextView 将当前文本呈现给所选单元格.
In the SecondViewController, I need to use the TextView to present the current text to the selected cell.
推荐答案
试试这个代码:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if(tableView == self.searchDisplayController!.searchResultsTableView){
if let cell: UITableViewCell = tableView.cellForRowAtIndexPath(indexPath){
if let cellTextLabel: UILabel = cell.textLabel{
let cellSelected = cellTextLabel.text!
// pass your segue name
self.performSegueWithIdentifier("segueToDetailVC", sender: cellTextLabel.text!)
}
}
}
传递数据
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "segueToDetailVC")
{
var str: String = sender as! String
// your ViewController class object
var detail: DetailVC = segue.destinationViewController as! DetailVC
// pass text in String Variable
detail.text = str
}
}
这篇关于如何使用 didSelectRowAtIndexPath(在 Swift 中)在两个 Storyboard 之间传递日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文