Table View to Detail View

Discussion in 'iOS Programming' started by hammy35, Apr 15, 2014.

  1. hammy35 macrumors newbie

    Joined:
    Apr 15, 2014
    #1
    Hello all!

    I'm new to this forum and new to iOS development. I started learning it a couple of weeks ago and I'm in the process of making my first app. My day job is a web developer so a lot of things I'm learning I'm thinking of it from a web development point of view.

    One thing that I've been looking at is going from a Table View Controller to a Detail View. Normally in web development, you would pass through an ID in the URL and use that ID to populate the Detail page. Is this the same in iOS development? Or would you pass through the object?

    Hopefully this isn't a really stupid question.:D
     
  2. Dookieman macrumors 6502

    Joined:
    Oct 12, 2009
    #2
    Not a stupid question.

    You can push to a detail view controller in a couple ways. One using a Segue, or a tableview delegate method that pushes to a designated view controller with a name you specify.

    Code:
    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ViewController *result = [self.storyboard instantiateViewControllerWithIdentifier:@"Details"];
    [self.navigationController pushViewController:result animated:YES];
    }
    
    "Details" is the name of the view controller that I gave it. It could be anything.
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    It depends on your data model. You'd pass through some information that provides the detail view with enough info to populate itself. This could be as simple as a string or integer that can map to a row in a database or it could be an object that has all the info required to display the detail view, or it could be a URL or file path that identify the content to be displayed. It may also depend on whether the detail view will be allowed to change what is stored in the data model or only display it.

    If your data model consists of a list of objects and the user has selected one of the rows that corresponds to one of the objects then it makes perfect sense to pass that single object to the detail view.
     
  4. MattInOz macrumors 68030

    MattInOz

    Joined:
    Jan 19, 2006
    Location:
    Sydney
    #4
    ^This^

    The trick is you want the Data object passed to Detailview to be rich enough with it's data that you could restore an instance of the Detailview with that data but simple enough that the masterview doesn't need to deal with too much data. You want to keep the views as independent as possible, so a simple ID that both can use to get just enough data from model is not a bad plan.
     

Share This Page