-2

I know I need to use didSelectRowAtIndexPath, but despite searching I can't seem to find a simple explanation.

I wish to use a TableView as an index for 10 other ViewControllers, but am having problems finding a simple resource that explains how to link each cell to a subsequent TableViewController.

jscs
  • 63,694
  • 13
  • 151
  • 195
Benjamxm
  • 49
  • 9
  • Exactly what you want? please clear explain in brief. – Saurabh Prajapati Nov 07 '14 at 04:17
  • Hey! Thank you for responding - I have a tableview with multiple cells. When a user clicks on a cell, I would like to navigate to a specific tableviewcontroller. – Benjamxm Nov 07 '14 at 04:24
  • instead of multiple tableViewController , you have to use only one! and pass the data to tableViewController which you want to show on click event of didselectrowAtIndexPath. – Saurabh Prajapati Nov 07 '14 at 04:28
  • Sorry, I think there is a little confusion. I don't need to pass any data, I simply need to navigate – Benjamxm Nov 07 '14 at 04:33
  • 1
    so what are you showing in tableviewController! – Saurabh Prajapati Nov 07 '14 at 04:52
  • 1
    Do you really need 10 different table view controllers (i.e. different subclasses of UITableViewController)? Usually you define one or maybe a couple subclasses to navigate to, and you set properties based on the selection that was made, i.e. in prepareForSegue. – shim Nov 07 '14 at 04:56
  • Hello @saurabh, thank you for your insights. I'm a noob, and as such it's a little hard to articulate using the correct vernacular. I really only need 1 subclass of UITableviewcontroller, but a searching for a way to display different data based on the initial user selection. e.g I have a database of exercises grouped by bodypart (category). When a user selects "Arms" in the parent, the child UITableviewcontroller displays every exercise for arms. Whereas if they select "legs", the child UITableviewcontroller displays every exercise for legs. – Benjamxm Nov 07 '14 at 05:42
  • are you getting array For bodyParts??e.g. array for "Arms" etc?? – Saurabh Prajapati Nov 07 '14 at 05:55
  • THANK YOU! so much of my time has been spent trying to articulate the problem in a way to get help... – Benjamxm Nov 07 '14 at 06:08

2 Answers2

1

Try this:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    println("You selected cell #\(indexPath.row)!")

    // Show your screen here 
}
Andrew T.
  • 4,701
  • 8
  • 43
  • 62
Abdul Yasin
  • 3,480
  • 1
  • 28
  • 42
0

if you are getting Dictionary for bodyParts then you should use like this: e.g.

NSDictionary *bodyparts; //containg data from database
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    let tblView = self.storyboard?.instantiateViewControllerWithIdentifier("Identifier") as UITableViewController
    switch(indexPath.row)
    {
        //data is array of tableviewcontorller
    case 0:
        tblView.Data = [bodyparts objectForKey:@"Arms"];//if You are getting array for key "Arms"
        break;
    case 1:
        tblView.Data = [bodyparts objectForKey:@"Legs"];
        break;
    and so on....
    default:
        break;
    }
}

you have to set storyboard identifier in storyboard

Saurabh Prajapati
  • 2,348
  • 1
  • 24
  • 42