I have a TableViewController and a ViewController. I am trying to link the two together and print a certain statement in the ViewController dependent on which row has been tabbed in the TableViewControler.
I declared a public variable called rowCounter and in the TableViewController class I set rowCounter equal to the row of the indexPath.
Then, in the TableViewController I am trying to use an if-statement to access the rowCounter variable and print a statement dependent on the number but I keep getting an 'expected declaration' error. What am I doing wrong?
Here's the code:
TableViewController:
import UIKit
var rowCounter: Int = 0
class TableTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
rowCounter = indexPath.row
return indexPath
}
ViewController:
import UIKit
class ViewController: UIViewController {
if rowCounter == 1 {
println("test")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}