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
最满意答案
在尝试使用控件之前,您必须确保在您的计算机上注册了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 ...
-
SQL Server 2005也安装了Visual Studio 2005吗?(SQL Server 2005 installs Visual Studio 2005 too?)[2023-02-18]
您获得的可视化工作室是一个名为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: ...
-
'查找所有引用'在visual studio 2005中不起作用('Find all references' not working in visual studio 2005)[2023-12-08]
删除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.
-
在Visual Studio 2008中使用Visual Studio 2005项目(Working with Visual Studio 2005 projects in Visual Studio 2008)[2024-02-14]
没有编辑.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目录中找到该文件的附加包含目录。 每当您指定一个额外的库(. ...
-
Visual Studio 2008 SP1和Visual SourceSafe 2005(Visual Studio 2008 SP1 and Visual SourceSafe 2005)[2023-10-07]
工具 - >选项 - >源控制 - >插件选择。 选择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内置的功能。 但是,这需要创建项目文件。 否则,似乎有人冒险与该工具进行艰苦的战斗。 测试的一个选项是通过自定义构建 ...