So I am trying to create a app that is more or less a reference with static data and using a plist to store the data
I have two TableViewControllers setup on the storyboard and I wanna pass the selected cells rownumber or its data to the next view?
My initial setup:
import UIKit
var categoryNames:NSArray = []
var categorySelected:String = ""
class ListForbTVC: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
let path = NSBundle.mainBundle().pathForResource("listor", ofType: "plist")
let dict = NSDictionary(contentsOfFile: path!)
categoryNames = dict.objectForKey("Category") as NSArray
println(categoryNames.count)
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
For some reason I cannot figure out how to count the number of rows in the array?
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 13
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel!.text = categoryNames[indexPath.row] as? String
return cell
}
What should I add here to actually pass the value through the segue? Would be neat to know how to both pass the index of the selected row and how to pass the actual value of it.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "listData" {
}
How do I recieve the information in the next view?
I have done this in obj-c and X-Code 5 but I cannot figure out how to do this in Swift.
Thanks in advance
categoryNames.count
is the number of elements in the array - you are already printing it. As for passing the data, simply declare a property on your destination view controller class and set it as you do in Objective C