首页 \ 问答 \ Prepareforsegue没有将适当的值传递给目标Viewcontroller?(Prepareforsegue not passing the appropriate value to destination Viewcontroller?)

Prepareforsegue没有将适当的值传递给目标Viewcontroller?(Prepareforsegue not passing the appropriate value to destination Viewcontroller?)

我有两个viewcontrollers(一个是tableVC),我想在其间传递信息。 这是tableVC的代码:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        var rowSelected = indexPath.row
        print(rowSelected) //always returns the correct integer

        func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

            let destViewController: newController = segue.destination as! newController
            newController.rowSelected = rowSelected
        }

        performSegue(withIdentifier: "rowSelected", sender: Any?.self)//segue to newController

    }

以下是我希望将信息传递给newController的代码:

 @IBOutlet weak var label: UILabel!

var rowSelected = Int()
override func viewDidLoad() {
    super.viewDidLoad()

    label.text = infoArray[rowSelected]

    print(rowSelected) //always logs 0 to the console, regardless of cell selection

}

我以为我已经适当地设置了它,但无论出于何种原因,无论在tableVC中选择了什么单元格,调用infoArray的索引始终为0。 不确定是什么问题。


I have two viewcontrollers (one is tableVC) that I would like to pass information between. Here is code from that tableVC:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        var rowSelected = indexPath.row
        print(rowSelected) //always returns the correct integer

        func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

            let destViewController: newController = segue.destination as! newController
            newController.rowSelected = rowSelected
        }

        performSegue(withIdentifier: "rowSelected", sender: Any?.self)//segue to newController

    }

And here is the code for the newController that I want the info to be passed to:

 @IBOutlet weak var label: UILabel!

var rowSelected = Int()
override func viewDidLoad() {
    super.viewDidLoad()

    label.text = infoArray[rowSelected]

    print(rowSelected) //always logs 0 to the console, regardless of cell selection

}

I thought I had set this up appropriately, but for whatever reason the index called to the infoArray is always 0, no matter what cell is selected in the tableVC. Not sure what the problem is.


原文:https://stackoverflow.com/questions/40582206
更新时间:2023-08-23 15:08

最满意答案

在尝试使用控件之前,您必须确保在您的计算机上注册了ajax 1.0.20229.20821

你可以在这里找到它: http//msdn.microsoft.com/en-us/library/bb861898(v = office.12).aspx


You have to make sure ajax 1.0.20229.20821 is registered on your machine before trying to use the controls

You can find it here: http://msdn.microsoft.com/en-us/library/bb861898(v=office.12).aspx

相关问答

更多
  • 这里有更多的链接: http : //social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/290fb587-1447-466c-9149-a692fa5de34d他们似乎指向相同的文件。 直接下载链接: http : //go.microsoft.com/fwlink/?LinkId=51411&clcid=0x409 Here are more links: http://social.msdn.microsoft.com/Forums/e ...
  • 您获得的可视化工作室是一个名为Business Intelligence Development studio的shell,它允许您创建Analysis Services,Integration Services和Reporting Services项目。 它还允许您将这些项目部署到SQL Server。 如果已安装Visual Studio,则会将这些项目类型添加到其中。 使用Development Studio,您可以将C.Net项目(如C#或VB)添加到Analysis Services或Report ...
  • 在尝试使用控件之前,您必须确保在您的计算机上注册了ajax 1.0.20229.20821 你可以在这里找到它: http : //msdn.microsoft.com/en-us/library/bb861898(v = office.12).aspx You have to make sure ajax 1.0.20229.20821 is registered on your machine before trying to use the controls You can find it here: ...
  • 删除Debug或Release子目录中的.ilk , .pch和.pdb文件。 然后build all 。 它应该重新构建并在此之后工作,特别是在重新安装VS之后。 Delete the .ilk, .pch, and .pdb files in the Debug or Release subdirectory. Then do build all. It should reconstitute and work after that, especially after reinstalling VS.
  • 你有没有更新你的Windows SDK到最新版本? 由于这是一个Windows API函数,因此它应该包含在那里。 Did you update your Windows SDK to the most recent version? Since this is a Windows API function, it should be included there.
  • 没有编辑.csproj文件就无法做到这一点。 您需要更改项目标题中的“ToolsVersion”属性。 You can't do this without editing the .csproj files. You'll need to change the "ToolsVersion" attribute in the project header.
  • 是的,2005年和2008年之间的项目文件是兼容的。 解决方案不是,但那些很容易重制或复制。 如果您使用的是Web应用程序项目,那么项目文件就有一个问题。 这两个版本引用不同的MSBuild目标文件。 史蒂文哈曼有一个修补程序添加到项目文件的博客 。 只要你没有使用3.5编译器中的新东西,你应该是好的。 请注意,即使您的目标是2.0 Framework,编译器仍然会接受3.5语法(var,对象初始值设定等),所以您仍然需要了解这些。 Yes, the project files between 2005 a ...
  • 起初我对此感到困惑,并且MSDN没有很好地解释它。 您最好的学习方法是尝试使用VS2008指令(如boost)链接到库。 无论如何,其他包含目录在Project-> Properties-> C ++ - > General中,其他库在Project-> Properties-> Linker-> General中。 您可以在Properties-> Linker-> Input下将库名放在其他库中。 因此,无论何时包含文件,它都会在Include目录中找到该文件的附加包含目录。 每当您指定一个额外的库(. ...
  • 工具 - >选项 - >源控制 - >插件选择。 选择Microsoft Visual SourceSafe Tools->Options->Source Control->Plug-in Selection. Select Microsoft Visual SourceSafe
  • 据我所知,没有将Ant脚本转换为NAnt的自动方式。 但是,由于NAnt基于Ant,因此只要任务是“核心”任务,转换过程就不会与原始过程相差太远。 可能会在Ant脚本上进行XSLT转换,以转换为NAnt,因为它们都是XML。 如果要沿着这条路走下去,那么转换应该基于原始Ant脚本动态完成,因此只需要维护一组脚本。 如果您想在Visual Studio中编写和编译C ++代码,那么很难超越IDE内置的功能。 但是,这需要创建项目文件。 否则,似乎有人冒险与该工具进行艰苦的战斗。 测试的一个选项是通过自定义构建 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)