0

I'm following Apple sample code "MultipleDetailViews" but what I want to do is that:

  1. at start, shows the RootViewController (table view) display the default detailViewController (1st detailView)
  2. when user selected a table cell, push into the stack, display the SubCategoriesVC (table view) in the master of the splitView but don't update the detailView.
  3. in SubCategoriesVC, selecting a table cell.. update the detailViewController (2nd detailView)

So, in RootViewController.m, I push another navigation ...

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    SubCatVC *browseSubCatView = [[SubCatVC alloc] initWithNibName:@"SubCatVC" bundle:nil];
    [self.navigationController pushViewController:browseSubCatView animated:YES];
    [browseSubCatView release];
}

Then, in SubCatVC.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 UIViewController <SubstitutableDetailViewController> *detailViewController = nil;      
 SecondDetailViewController *newDetailViewController = [[SecondDetailViewController alloc] initWithNibName:@"SecondDetailViewController" bundle:nil];
    detailViewController = newDetailViewController;

 // Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
self.splitViewController.viewControllers = viewControllers;
[viewControllers release];

// Dismiss the popover if it's present.
if (self.popoverController != nil) {
    [self.popoverController dismissPopoverAnimated:YES];
}

// Configure the new view controller's popover button (after the view has been displayed and its toolbar/navigation bar has been created).
if (self.rootPopoverButtonItem != nil) {
    [detailViewController showRootPopoverButtonItem:self.rootPopoverButtonItem];
}

  [detailViewController release];
  [[NSNotificationCenter defaultCenter] postNotificationName:@"updateProduct" object:nil];
}

but it didn't update my detailView.. so I don't know what's wrong? Src here: http://pastebin.com/iy6SqLqt

Hope someone can advise me. Thanks

Piotr Byzia
  • 3,363
  • 7
  • 42
  • 62
jayr parro
  • 286
  • 3
  • 18

1 Answers1

0

I Have not looked at your source, but but a common problem with Split views are delegates.

When you Push a new rootController ont the nav stack, you need to make sure it has the pointer to the detailViewController that you want it to talk to. You can check htis my logging the delegate before you try to update it:

In your SubCatVC (or any root for that matter):

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

//do stuff, init alloc vc's....

NSLog(@"DELEGATE: %@",self.delegate);

//push/delegate etc..

}

If you find its nil, copy the original roots delegate, or when your putting your new detail in, notify/set the root you want to comunicate with it.

If you need any more detail, just ask.

Luke Mcneice
  • 3,012
  • 4
  • 38
  • 50
  • Luke,thanks for response. I've change my SubCatVC to SubCatVC : UITableViewController so the delegate is working fine. Other problem I have is that when in selecting on the cell of SubCatVC; popover controller is null.. how I can pass it? or if you have any code/tutorial you can share would be much better.. tnx – jayr parro Dec 14 '10 at 06:50
  • In General, in objective-c, you can pass pointers anywhere. Make a property on your ViewC (that doesn't have the PopC) and set it after your init it. In this case, its fine although, you should always think about it first- Could the Parent of the object pointer die before the object you passed it gets to use it? – Luke Mcneice Dec 14 '10 at 08:43
  • Luke,I know how to pass pointer..I'm just wondering why the popover & the popover barbuttonItem is Null. I've post (attached) the code here (MultiDetailSplitFSG.zip) : http://www.iphonedevsdk.com/forum/iphone-sdk-development/66673-splitview-help.html ... hope you can check pls & advise me what's wrong.. i'm really stucked with this..tnx n advanced. – jayr parro Dec 15 '10 at 04:16