This is my situation. I'm using NSTimer, which counts 15 seconds but I have also button, which I use to stop this timer earlier. What's more this button takes me to the next tableViewController. The second parameter is date - current time in Center European. If I click a button I need to move to the next TableViewController, and put this two parameters to the TableViewController. This is my code:
**FirstViewController:**
import UIKit
class FirstViewController: UIViewController {
var timer = NSTimer()
@IBOutlet weak var labelCounter: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
timer = NSTimer.scheduledTimerWithTimeInterval(1,target:self, selector: Selector("update"),userInfo: nil, repeats :true)
}
func update(){
timer.invalidate()
}
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if (segue.identifier == "segueTest") {
var transfer = segue!.destinationViewController as SecondViewController
transfer.toPass = labelCounter.text
transfer.toPass2 = "\(NSDate())"
}
}
@IBAction func buttonPressed(button: UIButton){
if labelCounter.text > "0" {
timer.invalidate()
}
SecondViewController:
import UIKit
class ThirdViewController: UIViewController {
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var label2: UILabel!
var toPass: String!
var toPass2: String!
override func viewDidLoad() {
super.viewDidLoad()
label1.text = toPass2
label2.text = toPass
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
This code work fine :) In storyboard i had to connect firstViewController with SecondViewController. I did that by connected my button with the secondViewController and setting the segue identifier to "segueTest"