1

I need some help on displaying data from Master view to Details view. When a cell is selected on Master view, data will display on details viewMaster Details View

All other class is a xib file to be loaded on the Details view which is being outlet in the container view. The implementation is to avoid using UISplitViewController. I'm using objective-c. Please can anyone help me.

MainContainerViewController.m

+ (MainContainerViewController *)createModalContainer:(NSString*)paramStr{

    MainContainerViewController *aController = [[MainContainerViewController alloc] initWithNibName:@"MainContainerViewController" bundle:nil];

    aController.title = paramStr

    return aController;
}
- (void)viewDidLoad {
    [super viewDidLoad];

    _masterViewController = [[MasterViewController alloc]init];

    [_masterTableView setDataSource:_masterViewController];
    [_masterTableView setDelegate:_masterViewController];

    _masterViewController.view = _masterViewController.tableView;
}

MasterViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
            DetailsProfileViewController *detailsController = [[DetailsProfileViewController alloc] init];
            detailsController.title = @"Details";

            MainContainerViewController *container = MainContainerViewController.sharedInstance;

            [container.detailsTableView setDataSource:detailsController];
            [container.detailsTableView setDelegate:detailsController];

            detailsController.view = detailsController.tableView;

            [container.detailsTableView reloadData];
        break;
    }
}
bethinker
  • 11
  • 5
  • I think you should implement a protocol to handle this. – MD. Apr 13 '16 at 07:42
  • Please edit your post to show whatever code you have so far, and explain the exact problems you are having. Also, can you confirm whether you have two tables in the container view controller, or two table view controllers (each with their own table) embedded in the container VC? Why are you trying to avoid `UISplitViewController`? – pbasdf Apr 13 '16 at 08:27
  • because the source code is already exist and the client don't want to break the existing structure. – bethinker Apr 13 '16 at 08:58
  • Use prepareForSegue method to pass data from one view to other...check this http://stackoverflow.com/a/29360924/3535399 – vivek takrani Apr 13 '16 at 09:44
  • @bethinker Thanks for posting the code. What problems are you having? I think your `detailsController` is probably being deallocated as soon as the `didSelectRowAtIndexPath` method completes, because you don't have a strong reference to it. Try making `detailsController` a property. – pbasdf Apr 13 '16 at 17:22
  • I tried that also and i didn't work but it did trigger the viewDidLoad method of a class but no display on the tableview – bethinker Apr 14 '16 at 03:26
  • I mean the dataSource and delegate is not triggered – bethinker Apr 14 '16 at 03:36

0 Answers0