ios - 如何将选定的行数据传递给另一个 ViewController

标签 ios swift

我有一个像这样的桌面 View

enter image description here

我想获取链接并将其传递给另一个控件 View 。

这是我所做的

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {


    let linktopass = classes[indexPath.row].valueForKey("link")
    print(linktopass)


    func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        let thirdVC: web = segue.destinationViewController as! web

        thirdVC.link = linktopass as! String

但它不起作用。

这是我的打印输出。

Optional( http://blablabla )

最佳答案

如果您认为您忘记了在didSelectRowAtIndexPathperformsegue

prepareForSegue 在您 performsegue 之前被调用。如果您不执行 segue,那么您的 prepareForSegue 将不会被调用。

因此,在 didSelectRowAtIndexPath 中,添加如下代码,

  performSegueWithIdentifier("goToNextVC", sender: self) //your segue identifier here
  //goToNextVC is segue identifier set from attribute inspector from storyboard

确保您已经从属性检查器设置了segue标识符。

您可以设置标识符,例如,

选择segue - 点击属性检查器 - 在其中写入标识符 - 按回车

希望这会有所帮助:)

关于ios - 如何将选定的行数据传递给另一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37307717/

相关文章:

iphone - UITextField 限制字符的数量和类型

ios - 如何显示过滤后的对象数组的计数

ios - 不需要更新 Realm 中的对象

ios - dateFormat 错误返回 nil

objective-c - 如何在iOS5/XCode 4.3中导入QuartCore?

cocoa-touch - iOS:按钮的非方形点击区域

ios - guard let in swift 2.0 playground 获取关于可选绑定(bind)的错误...为什么?

ios - Google Sign In iOS 无法登录

ios - CLLocationCooperative2D 到 LocationList

ios - 基于CGPoint在屏幕上绘制UIView