我在我的"开始"图
import Foundation
import UIKit
class ThirdView : UITableViewController {
var jsonz:NSArray = ["Ray Wenderlich"];
var valueToPass : String?;
var programVar : String?;
override func viewDidLoad() {
super.viewDidLoad()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
var newProgramVar = "lol";
let destinationVC = segue.destinationViewController as! FourthView
destinationVC.programVar = newProgramVar
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1;
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.jsonz.count;
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let myCell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
myCell.textLabel?.text = self.jsonz[indexPath.row] as? String;
return myCell;
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let valueToPass = "asd";
let destinationVC = FourthView()
destinationVC.valuePassed = valueToPass;
self.performSegueWithIdentifier("restDetail", sender: tableView);
}
}
当我运行一个项目并点击单元格时,我无法在"第二个"中收到变量 valuePassed 。看来,我没事了。请帮忙,为什么? 但我正常从函数prepareForSegue接收变量 programVar ,没关系。我对didSelectRowAtIndexPath segue只有问题。
这是我的第四视图:
import UIKit
class FourthView: UIViewController {
var valuePassed:String!
var programVar:String!
override func viewDidLoad() {
super.viewDidLoad()
println(valuePassed);
println(programVar);
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
请在此处查看我的输出内容:
nil
lol
nil
lol
第二个问题:为什么输出显示4次? 抱歉我的英文。