12

I'm little lost here. I have a basic master-detail aplication, and I want to change the detail view according to the selected row in MasterViewController, but the views have different content, one has an image gallery, and the other one will load a video on full screen. It's not just refresh the detail view, have to load another view. How is the better(fast) way to do that?

bneely
  • 9,003
  • 4
  • 36
  • 46
Vinícius Albino
  • 403
  • 6
  • 21

3 Answers3

17

I'll suggest you to use a replace segue.

Just create a segue to the desired view initiated by your row with a Style: Replace, and Destination: Detail Split.

Segues were introduced in the iOS 5 SDK

EDIT:

These are step-by-step instructions to accomplish what you need. From now on:

  • the item that should be pressed for the action to take place (a button or row in master view) = *Button;
  • the view you want to be placed in the iPad's detail view = *Detail.

just a bit for naming for ease of explanation

  1. Hold ctrl click on *Button then hold and drag to *Detail and release to create your segue.
  2. In the popup pick Replace
  3. Select your segue, open Attributes inspector and set Destination to Detail Split

That's all.

More on segues: http://www.scott-sherwood.com/?p=219

Uko
  • 12,209
  • 6
  • 53
  • 102
  • Still cant understand, so far all examples ive seem the detail view is, always have the same content,changing only one image or some text.Do you have any example or tutorial on how to do that you just said? – Vinícius Albino Feb 21 '12 at 03:52
  • 1
    @user1108474 do you know what is _iTunes U_? It has very nice stanford classes on iPhone and iPad development. Also you can check our the next app: http://www.stanford.edu/class/cs193p/cgi-bin/drupal/system/files/sample_code/Psychologist%20with%20Dr%20Pill_0.zip the thing that you need is done by _Dr Pill_ view (when u press the buttons). Also I'll add more detailed description in my answer – Uko Feb 21 '12 at 13:10
  • Uko... you're the man! You saved my bacon! I have been fighting this for 3 days now, nobody seems to either know the answer, or cares to answer. I truly appreciate your time answering this. Regards, Spokane-Dude – SpokaneDude Feb 25 '12 at 17:41
  • You are welcome! Have a nice day :) By the way, can you mark this answer as correct? – Uko Feb 25 '12 at 20:55
  • I found almost nothing about `replace` segues. Are they limited to split view controllers? I have a pane in my iPad app the content of which must change depending on which button is pressed. It doesn't use a master-detail UI. Can I use a `replace` segue to switch the pane view? If not, what would be the best way to storyboard that? Thanks. – Jean-Denis Muys Mar 09 '12 at 10:28
  • @Jean-DenisMuys yes, ass far as I know _replace_ type of segue is specific to split view controller. Your comment qualifies for another question, but what can I suggest 1) use a split view controller 2) use some method or other stuff to change the content 3) generate instantiate needed controller on the go. – Uko Mar 09 '12 at 18:23
  • 1
    I now have a split view controller and this works... except that the replaced detail views do not have the navigation bar, thus no popover button. Any idea what I missed? – Jean-Denis Muys Oct 05 '12 at 13:14
  • @Jean-DenisMuys is the navbar a part of navigation view controller or I've added it just as a subview? It's it's a part of nav-view controller then be sure that you're segueing into it an not into some of it's sub controllers. If my suggestion won't solve your problem please try to be more specific. Maybe you should ask another question about this to be able to describe your problem in details. – Uko Oct 05 '12 at 15:35
1

Specifically, in CS193P, check out the latest version, and look at lecture #7. Paul doesnt finish the part with the replace Segue, but he DOES provide an example with very good reusable code (Psychologist with Dr Pill)

JMattos
  • 202
  • 1
  • 2
  • 13
1

If you are using a dynamic tableview in your MasterViewController, implement numberOfRowsInSection:(NSInteger)section Method with:

return [_youDataArrayNameHere count];

then on cellForRowAtIndexPath configure the cell:

cell.textLabel.text = [_youDataArrayNameHere  objectAtIndex:indexPath.row];

and in didSelectRowAtIndexPath, call any other view based on the selected row:

//
if (indexPath.row == 0) {
     [_detailViewController.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"anotherVC01Here"] animated:YES];
}
LAOMUSIC ARTS
  • 642
  • 2
  • 10
  • 15