I thought I'd have a go at building an ipad app using swift. The app that I'm mucking around with is a master-detail app. In the master table I have 2 rows: "Window1" and "Window2" and two detail views. I have created a storyboard segue to the two detail views (1 being the default one). The two segues are called "showDetail" and "showWindow2".
A video I was watching on youtube used the following code to direct the user from the master tab to the appropriate detail page:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
var row = indexPath.row
switch row
{
case 1:
self.performSegueWithIdentifier("showDetail", sender: self)
default:
self.performSegueWithIdentifier("showWindow2", sender: self)
}
}
which works when I have only two rows in the master page. The above code doesn't seem to work when I have 3 rows on the master page (by adding a row with the label "Window3"):
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
var row = indexPath.row
switch row
{
case 1:
self.performSegueWithIdentifier("showDetail", sender: self)
case 2:
self.performSegueWithIdentifier("showWindow2", sender: self)
default:
self.performSegueWithIdentifier("showWindow2", sender: self)
}
}
The issue I think I'm having is that value of "row" seems to change depending on which row I am currently on. By this I mean when I am debugging, the row value when selecting either "Window1", "Window2", or "Window3" seems to vary between 0, 1, and 2 and my code does not result in the correct detail page being shown.
I don't know what I'm missing here. Can anyone please help me out?