简体   繁体   English

将数据从 tableview 单元格传递到 View Controller Swift 2.1

[英]Passing data from tableview cell to View Controller Swift 2.1

变量“sendTitle”无法访问

Anyone know why can't I access the variable 'sendTitle' in prepareForSegue from didSelectRowAtIndexPath?任何人都知道为什么我不能从 didSelectRowAtIndexPath 访问 prepareForSegue 中的变量“sendTitle”? I saw some of the tutorials, they are doing the same thing with me, I've no idea why mine got error.我看了一些教程,他们和我做同样的事情,我不知道为什么我的会出错。 --What I'm doing now is passing value from tableView cell to another view controller. --我现在正在做的是将值从 tableView 单元格传递到另一个视图控制器。

I'm using Xcode 7 Swift 2.1我正在使用 Xcode 7 Swift 2.1

Because it is declared privately in your didSelectRowAtIndexPath method.因为它是在您的didSelectRowAtIndexPath方法中私下声明的。 It won't be accessible outside of those function.在这些功能之外无法访问它。 if you want to access it from another function, declare it as global variable in your view controller.如果要从另一个函数访问它,请在视图控制器中将其声明为全局变量。

you have to declare sendTitle inside your class to make it visible to all methods.您必须在类中声明 sendTitle 以使其对所有方法可见。 Something like follows.类似的东西如下。

import UIKit

class viewController: UITableViewController {
   var sendTitle:String = ""

   override func viewDidLoad() {
       super.viewDidLoad()
   }

   //table view delegate methods 
   // just use sendTitle = cell.lblTitle.text!

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 快速将TableView单元中的数据传递给视图控制器 - Swift Passing Data in a tableview cell to a view controller 将字符串从TableView单元格传递到Swift 3中的View Controller - Passing a string from a TableView cell into a View Controller in Swift 3 ios Swift:将数据从tableView传递到视图控制器 - ios Swift: Passing data from tableView to view controller 数据将tableview单元格传递到Swift中的标签栏视图控制器 - Data pass tableview cell to tab bar view controller in Swift Swift:当用户点击Tableview单元格时,如何将数据从一个视图控制器转移到另一个 - Swift: How to SHIFT data from one view controller to another when the user taps on the Tableview Cell 将数据从自定义表格视图单元传递到UIView控制器 - Passing Data from custom tableview cell to UIView controller 将数据从集合视图单元格按钮传递到另一个视图控制器(Swift) - Passing data from a collection view cell button to another view controller (Swift) Swift 4:将数据从集合视图单元格传递到另一个没有故事板的视图控制器 - Swift 4: Passing data from a collection view cell into another view controller without storyboards 在iOS Swift 2中将数据从视图控制器传递到表视图控制器 - Passing data from view controller to table view controller in ios swift 2 将数据从父视图控制器传递到子视图控制器Swift 4 - Passing Data From Parent View Controller to Child View Controller Swift 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM