本文介绍了快速数组中的prepareForSegue元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个viewcontrller vc1和vc2.在vc1中,它是使用json解析的tableview,并显示一些名称.
I have two viewcontrller vc1 and vc2. In vc1 it is tableview parsed with json and it displays some names.
vc1:
var names: [String] = [] // Displays name (Ana, Mike, John ....)
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TVC
cell.lable.text = name[indexPath.row]
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let someName: vc2 = segue.destinationViewController as! vc2
someName.nameFromVC1 = //need code here
}
vc2:
var nameFromVC1: String!
我的目标是当表显示名称时,我单击一些名称说"Ana",我希望将"Ana"发送到vc2并放入var nameFromVC1
my goal is when table displays names, and I click some name say "Ana", I want "Ana" to be sent to vc2 and put in var nameFromVC1
推荐答案
您应该在vc 1中使用类似的东西:
You should use something like this in vc 1:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Prepare the destination view controller with the selected name
(segue.destinationViewController as? NameDetailViewController)?
.prepareForName(
names[tableView.indexPathForSelectedRow!.row]
)
}
这在目标视图控制器中:
And this in your destination view controller:
func prepareForName(name: String) {
self.name = name
}
这篇关于快速数组中的prepareForSegue元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!