[英]Passing data from tableview cell to View Controller Swift 2.1
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.